我想首次启动app时显示初始Activity。 我在主Activity中编写了这样的代码:
@Override
public void onResume() {
super.onResume();
SharedPreferences p = getPreferences(Context.MODE_PRIVATE);
if (p.getBoolean(STATE_INIT, true)) {
Intent intent = new Intent(this, GenderActivity.class);
startActivityForResult(intent, REQUEST_1);
}
}
初始活动出现,然后应用程序崩溃。有人可以评论一下这个问题或者提出另一种显示应用初始活动的方法吗?
异常日志:
07-19 01:54:45.997 3494-3494/ru.j_soft.contact E/AndroidRuntime: FATAL EXCEPTION: main
Process: ru.j_soft.contact, PID: 3494
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.RadioGroup.getCheckedRadioButtonId()' on a null object reference
at ru.j_soft.contact.MainActivity.onSaveInstanceState(MainActivity.java:392)
at android.app.Activity.performSaveInstanceState(Activity.java:1298)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1289)
at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:4088)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3490)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3550)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-19 01:54:50.227 3494-3494/ru.j_soft.contact I/Process: Sending signal. PID: 3494 SIG: 9