Evening :)
I have a little problem...
As you can see in my code below, the Textview which i am trying to setText on, is getting me a Nullpointer :(
Is there anyone which can tell me what i am doing wrong ? :)
And the string s isnt null or, it is the view itself. It is working when setting the text in the oncreate().
Thanks..
public class smsShower extends Activity{ private TextView status; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.show); //status = (TextView)findViewById(R.id.status); status = (TextView)findViewById(R.id.status); } public void displayText(String s){ status.setText(s); } } smsReceiverclass:
public class smsreceiver extends BroadcastReceiver { private String str; private boolean received = false; private smsShower smsshow; @Override public void onReceive(Context context, Intent intent) { //---get the SMS message passed in--- Bundle bundle = intent.getExtras(); smsshow = new smsShower(); SmsMessage[] msgs = null; str = ""; if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i=0; i<msgs.length; i++){ msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]); if(msgs[i].getDisplayOriginatingAddress().equals("1990")) { received = true; str += msgs[i].getMessageBody().toString(); smsshow.displayText(str); } Layout:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/status" android:layout_alignParentTop="true" android:text="Status:" android:layout_height="match_parent" android:layout_width="match_parent"></TextView> </RelativeLayout> Error Log:
02-18 01:14:20.064: ERROR/AndroidRuntime(18964): Caused by: java.lang.NullPointerException 02-18 01:14:20.064: ERROR/AndroidRuntime(18964): at com.sms1990.smsShower.displayText(smsShower.java:36) 02-18 01:14:20.064: ERROR/AndroidRuntime(18964): at com.sms1990.smsreceiver.onReceive(smsreceiver.java:47) 02-18 01:14:20.064: ERROR/AndroidRuntime(18964): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2941)