我正在编写一个扩展,显示按钮单击的其他视图。我成功启动了该活动,但在 onCreate 活动上我正在设置内容视图,但出现此错误。我已将该活动包含在本机清单文件以及 flex 的 android 清单文件中
09-18 15:35:11.040: E/AndroidRuntime(7712): FATAL EXCEPTION: main
09-18 15:35:11.040: E/AndroidRuntime(7712): java.lang.RuntimeException: Unable to start activity ComponentInfo{air.TestAndroid.debug/com.aneexample.androiddialog.Second}: java.lang.NullPointerException
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.os.Looper.loop(Looper.java:123)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.app.ActivityThread.main(ActivityThread.java:3691)
09-18 15:35:11.040: E/AndroidRuntime(7712): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 15:35:11.040: E/AndroidRuntime(7712): at java.lang.reflect.Method.invoke(Method.java:507)
09-18 15:35:11.040: E/AndroidRuntime(7712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
09-18 15:35:11.040: E/AndroidRuntime(7712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
09-18 15:35:11.040: E/AndroidRuntime(7712): at dalvik.system.NativeStart.main(Native Method)
09-18 15:35:11.040: E/AndroidRuntime(7712): Caused by: java.lang.NullPointerException
09-18 15:35:11.040: E/AndroidRuntime(7712): at com.aneexample.androiddialog.Second.onCreate(Second.java:19)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-18 15:35:11.040: E/AndroidRuntime(7712): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
这就是我在 onCreate 方法上设置内容视图的方式。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
Log.d(TAG, "create Second activity");
super.onCreate(savedInstanceState);
FREContext freContext = AndroidDialogExtension.context;
setContentView(freContext.getResourceId("layout.second"));
}