title: Class Cast Exception problem
body: <p>i keep getting a class cast exception error when i run my program and i am not entirely sure why. </p>
  
  <p>error</p>
  
  <pre><code>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 to start receiver com.app.notifyme.SmsReciever: java.lang.ClassCastException: java.lang.String
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at android.app.ActivityThread.access$3200(ActivityThread.java:125)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at android.os.Handler.dispatchMessage(Handler.java:99)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at android.os.Looper.loop(Looper.java:123)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at android.app.ActivityThread.main(ActivityThread.java:4627)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at java.lang.reflect.Method.invokeNative(Native Method)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at java.lang.reflect.Method.invoke(Method.java:521)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at 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):     at android.app.ContextImpl$SharedPreferencesImpl.getInt(ContextImpl.java:2706)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at com.app.notifyme.SmsReciever.onReceive(SmsReciever.java:45)
  02-18 14:31:27.585: ERROR/AndroidRuntime(325):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
  </code></pre>
  
  <p>now if i read that right it is saying the error is at line 45 in SmsReciever which would make this the problem area.</p>
  
  <pre><code>SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
  unread = pref.getInt(SmsPrefs.COUNT, 0);
  </code></pre>
  
  <p>I have everything defined as such</p>
  
  <pre><code>private int unread = 0;
  //in preference class
  public static final String COUNT = "";
  </code></pre>
  
  <p>I am just trying to use this variable to keep a count. Someone guide me along here because i really dont see a problem.</p>
  
  <p><em><strong></em></strong><em>update</em><strong><em>*</em>**</strong></p>
  
  <p>how code is</p>
  
  <pre><code>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) &amp;&amp; smsOn == true){
              String from = new String();
              String body = new String();
  
              Bundle bundle = arg1.getExtras();
              if (bundle != null) {
                  Object[] pdus = (Object[]) bundle.get("pdus");
                  for (Object pdu : pdus){
                  SmsMessage messages = SmsMessage.createFromPdu((byte[]) pdu);
                  from = messages.getDisplayOriginatingAddress();
                  body= messages.getDisplayMessageBody();
                  }// end for
              }//end if
  
              int icon = 0;
              CharSequence tickerText = null;
              long when = 0;
              SharedPreferences.Editor editor = pref.edit();
  
              icon = icon(icon);
              tickerText = from + ": " + body;
              when = System.currentTimeMillis();
              CharSequence contentText = "";
              CharSequence contentTitle = "";
  
              /*
               if no notifications do normal
               else if notified &gt;= 1 and last message is from same person display name and how many messages
               else if(notified &gt;=1 and last message is from different display new message and how many
               */
              if(unread == 0){
                  contentTitle = from;
                  contentText = body.toString();
                  unread = 1;
                  editor.putInt(SmsPrefs.COUNT, unread);
                  editor.commit();
              }else if(unread &gt;= 1 &amp;&amp; mLast.equals(from)){
                  contentTitle = from;
                  contentText = unread + " unread messages";
                  unread++;
                  editor.putInt(SmsPrefs.COUNT, unread);
                  editor.commit();
              }else if(unread &gt;= 1 &amp;&amp; !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();
  </code></pre>
  
  <p>and in the preference activity I have count defined as i showed earlier, also tried putting something in the string but still the same result</p>