【发布时间】:2014-06-30 06:16:47
【问题描述】:
当我尝试启动此意图并显示我已经包含 setContentView(R.layout.activity_try_text); 的文本时,App Force 会关闭
public class TryText extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_try_text);
TextView text = (TextView)findViewById(R.id.textView11);
text.setText("hi");
}
}
这里是日志猫
06-30 12:03:05.115:I/Process(698):发送信号。 PID:698 SIG:9 06-30 12:03:11.802: D/AndroidRuntime(1327): 关闭虚拟机 06-30 12:03:11.802: W/dalvikvm(1327): threadid=1: 线程以未捕获的异常退出 (group=0x41b7bd40) 06-30 12:03:11.807:E/AndroidRuntime(1327):致命异常:主要 06-30 12:03:11.807: E/AndroidRuntime(1327): 进程: com.example.bag, PID: 1327 06-30 12:03:11.807: E/AndroidRuntime(1327): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.example.bag/com.example.bag.TryText}: java.lang.NullPointerException 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2269) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.ActivityThread.access$800(ActivityThread.java:139) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.os.Handler.dispatchMessage(Handler.java:102) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.os.Looper.loop(Looper.java:136) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.ActivityThread.main(ActivityThread.java:5102) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 java.lang.reflect.Method.invokeNative(Native Method) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 java.lang.reflect.Method.invoke(Method.java:515) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 06-30 12:03:11.807: E/AndroidRuntime(1327): at dalvik.system.NativeStart.main(Native Method) 06-30 12:03:11.807:E/AndroidRuntime(1327):原因:java.lang.NullPointerException 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.view.ViewGroup.addViewInner(ViewGroup.java:3561) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.view.ViewGroup.addView(ViewGroup.java:3415) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.view.ViewGroup.addView(ViewGroup.java:3391) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:299) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.Activity.setContentView(Activity.java:1957) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:220) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:106) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:81) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 com.example.bag.TryText.onCreate(TryText.java:21) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.Activity.performCreate(Activity.java:5248) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110) 06-30 12:03:11.807: E/AndroidRuntime(1327): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2173) 06-30 12:03:11.807: E/AndroidRuntime(1327): ... 11 更多
【问题讨论】:
标签: setcontentview