当我尝试启动此意图并显示我已经包含的文本时,App Force 会关闭setContentView(R.layout.activity_try_text);
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");
}
}
这是logcat
06-30 12:03:05.115: I/Process(698): 发送信号。PID: 698 SIG: 9 06-30 12:03:11.802: D/AndroidRuntime(1327): 关闭 VM 06-30 12:03:11.802: W/dalvikvm(1327): threadid=1: 线程退出未捕获异常(group=0x41b7bd40) 06-30 12:03:11.807: E/AndroidRuntime(1327): 致命异常: main 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: