嗨,我正在使用 android。如何在异步任务的 Onpostexecution 中使用 setContentview ??我使用了代码
if (getIntent().hasExtra("key")) {
if(key.compareTo(App_id)==0)
{
setContentView(R.layout.home);
}
}
else {
finish();
}
但它强制关闭并显示错误空指针异常。如何在 onpost 执行中使用 setcontentview?
这是我的 logcat 输出
03-20 13:47:30.270: E/AndroidRuntime(1628): FATAL EXCEPTION: main
03-20 13:47:30.270: E/AndroidRuntime(1628): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.meetap.AdHome}: java.lang.NullPointerException
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.ActivityThread.access$600(ActivityThread.java:122)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.os.Looper.loop(Looper.java:137)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-20 13:47:30.270: E/AndroidRuntime(1628): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 13:47:30.270: E/AndroidRuntime(1628): at java.lang.reflect.Method.invoke(Method.java:511)
03-20 13:47:30.270: E/AndroidRuntime(1628): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-20 13:47:30.270: E/AndroidRuntime(1628): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-20 13:47:30.270: E/AndroidRuntime(1628): at dalvik.system.NativeStart.main(Native Method)
03-20 13:47:30.270: E/AndroidRuntime(1628): Caused by: java.lang.NullPointerException
03-20 13:47:30.270: E/AndroidRuntime(1628): at com.example.meetap.AdHome.onCreate(AdHome.java:374)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.Activity.performCreate(Activity.java:4465)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
03-20 13:47:30.270: E/AndroidRuntime(1628): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
03-20 13:47:30.270: E/AndroidRuntime(1628): ... 11 more
编辑:
我NullPointerException
有
Button close=(Button)findViewById(R.id.close);
close.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
finish();
}
});