android - Class Cast Exception problem -


i keep getting class cast exception error when run program , not entirely sure why.

error

02-18 14:31:27.585: error/androidruntime(325): fatal exception: main 02-18 14:31:27.585: error/androidruntime(325): java.lang.runtimeexception: unable start receiver com.app.notifyme.smsreciever: java.lang.classcastexception: java.lang.string 02-18 14:31:27.585: error/androidruntime(325):     @ android.app.activitythread.handlereceiver(activitythread.java:2821) 02-18 14:31:27.585: error/androidruntime(325):     @ android.app.activitythread.access$3200(activitythread.java:125) 02-18 14:31:27.585: error/androidruntime(325):     @ android.app.activitythread$h.handlemessage(activitythread.java:2083) 02-18 14:31:27.585: error/androidruntime(325):     @ android.os.handler.dispatchmessage(handler.java:99) 02-18 14:31:27.585: error/androidruntime(325):     @ android.os.looper.loop(looper.java:123) 02-18 14:31:27.585: error/androidruntime(325):     @ android.app.activitythread.main(activitythread.java:4627) 02-18 14:31:27.585: error/androidruntime(325):     @ java.lang.reflect.method.invokenative(native method) 02-18 14:31:27.585: error/androidruntime(325):     @ java.lang.reflect.method.invoke(method.java:521) 02-18 14:31:27.585: error/androidruntime(325):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 02-18 14:31:27.585: error/androidruntime(325):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 02-18 14:31:27.585: error/androidruntime(325):     @ dalvik.system.nativestart.main(native method) 02-18 14:31:27.585: error/androidruntime(325): caused by: java.lang.classcastexception: java.lang.string 02-18 14:31:27.585: error/androidruntime(325):     @ android.app.contextimpl$sharedpreferencesimpl.getint(contextimpl.java:2706) 02-18 14:31:27.585: error/androidruntime(325):     @ com.app.notifyme.smsreciever.onreceive(smsreciever.java:45) 02-18 14:31:27.585: error/androidruntime(325):     @ android.app.activitythread.handlereceiver(activitythread.java:2810) 

now if read right saying error @ line 45 in smsreciever make problem area.

sharedpreferences pref = preferencemanager.getdefaultsharedpreferences(context); unread = pref.getint(smsprefs.count, 0); 

i have defined such

private int unread = 0; //in preference class public static final string count = ""; 

i trying use variable keep count. guide me along here because dont see problem.

update***

how code is

public class smsreciever extends broadcastreceiver {  static final string action = "android.provider.telephony.sms_received";  notificationmanager notifymanag;  string mlast = new string(); private int unread = 0;  @override public void onreceive(context arg0, intent arg1) {      boolean smson = false;     string smscolor = new string ("green");     uri smssound;     string smsvibrate = new string ("normal");       sharedpreferences pref = preferencemanager.getdefaultsharedpreferences(arg0);       smson = pref.getboolean("pref_sms_on", false);      smscolor = pref.getstring("sms_pref_color", "green");      smssound = uri.parse(pref.getstring("sms_pref_sound", "silent"));      smsvibrate = pref.getstring("sms_pref_sound", "normal");      unread = pref.getint(smsprefs.count, 0);      mlast = pref.getstring(smsprefs.last, "");         notificationmanager mnotificationmanager = (notificationmanager) arg0.getsystemservice(context.notification_service);         if (arg1.getaction().equals(action) && smson == true){             string = new string();             string body = new string();              bundle bundle = arg1.getextras();             if (bundle != null) {                 object[] pdus = (object[]) bundle.get("pdus");                 (object pdu : pdus){                 smsmessage messages = smsmessage.createfrompdu((byte[]) pdu);                 = messages.getdisplayoriginatingaddress();                 body= messages.getdisplaymessagebody();                 }// end             }//end if              int icon = 0;             charsequence tickertext = null;             long when = 0;             sharedpreferences.editor editor = pref.edit();              icon = icon(icon);             tickertext = + ": " + body;             when = system.currenttimemillis();             charsequence contenttext = "";             charsequence contenttitle = "";              /*              if no notifications normal              else if notified >= 1 , last message same person display name , how many messages              else if(notified >=1 , last message different display new message , how many              */             if(unread == 0){                 contenttitle = from;                 contenttext = body.tostring();                 unread = 1;                 editor.putint(smsprefs.count, unread);                 editor.commit();             }else if(unread >= 1 && mlast.equals(from)){                 contenttitle = from;                 contenttext = unread + " unread messages";                 unread++;                 editor.putint(smsprefs.count, unread);                 editor.commit();             }else if(unread >= 1 && !mlast.equals(from)){                 contenttitle = "new messages";                 contenttext = unread + " unread messages";                 unread++;                 editor.putint(smsprefs.count, unread);                 editor.commit();             }              mlast = from;             editor.putstring(smsprefs.last, mlast);             editor.commit(); 

and in preference activity have count defined showed earlier, tried putting in string still same result

what storing in preferences count? think may have stored int value string accidentally.

like think there in code:

int = 1; prefs.putint(count, a); string last = ""; prefs.putstring(last, "name"); prefs.commit(); ... 

and later on doing prefs.getint(count) should fail doing because last , count resolve same key.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -