私は自分の論文に取り組んでいて、SMS の受信に行き詰まっています。メッセージ本文をブロードキャストレシーバーからアクティビティに渡し、アクティビティでメッセージをトーストすることができました。ただし、複数の画像ボタンがあり、特定の画像ボタンはメッセージ本文に基づいて変更されます。私のコードは次のようになります。
public String message;
.
.
.
//in my onCreate
.
.
.
Intent intent = getIntent();
message=intent.getStringExtra("messagefrombroadcastreceiver");
//Toast message here
if(message.equals("1")){
//set imagebutton1
}else if(message.equals("2")){
//set imagebutton2
}
.
.
.
.
アプリはメッセージをトーストできましたが、if-else-if 部分を追加すると強制終了します。私は本当に私が間違っているのか分かりません
LOGCATは...
01-24 18:39:35.271: W/dalvikvm(30941): threadid=1: thread exiting with uncaught exception (group=0x400f1560)
01-24 18:39:35.341: E/AndroidRuntime(30941): FATAL EXCEPTION: main
01-24 18:39:35.341: E/AndroidRuntime(30941): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thesistrial1/com.example.thesistrial1.Thesis}: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Looper.loop(Looper.java:130)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.main(ActivityThread.java:3735)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invoke(Method.java:507)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
01-24 18:39:35.341: E/AndroidRuntime(30941): at dalvik.system.NativeStart.main(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): Caused by: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.example.thesistrial1.Thesis.onCreate(Thesis.java:63)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
01-24 18:39:35.341: E/AndroidRuntime(30941): ... 11 more
01-24 18:39:35.341: E/AndroidRuntime(30941): [Blue Error Handler] Make Debugging Report file for main
01-24 18:39:35.341: E/AndroidRuntime(30941): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.thesistrial1/com.example.thesistrial1.Thesis}: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1658)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1674)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:942)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.os.Looper.loop(Looper.java:130)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.main(ActivityThread.java:3735)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invokeNative(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): at java.lang.reflect.Method.invoke(Method.java:507)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:662)
01-24 18:39:35.341: E/AndroidRuntime(30941): at dalvik.system.NativeStart.main(Native Method)
01-24 18:39:35.341: E/AndroidRuntime(30941): Caused by: java.lang.NullPointerException
01-24 18:39:35.341: E/AndroidRuntime(30941): at com.example.thesistrial1.Thesis.onCreate(Thesis.java:63)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-24 18:39:35.341: E/AndroidRuntime(30941): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
01-24 18:39:35.341: E/AndroidRuntime(30941): ... 11 more