80,362
社区成员
发帖
与我相关
我的任务
分享
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<CheckBox
android:id="@+id/eatId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="吃饭" />
<CheckBox
android:id="@+id/sleepId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="睡觉" />
<CheckBox
android:id="@+id/dota"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dota" />
</LinearLayout>
package com.xxm.view.checkbox;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.CheckBox;
public class MainActivity extends Activity {
private CheckBox eatBox;
private CheckBox sleepBox;
private CheckBox dotaBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//加上下面的就出错
eatBox=(CheckBox) eatBox.findViewById(R.id.eatId);
sleepBox=(CheckBox) sleepBox.findViewById(R.id.sleepId);
dotaBox=(CheckBox) dotaBox.findViewById(R.id.dota);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
05-09 09:14:21.406: E/Trace(1204): error opening trace file: No such file or directory (2)
05-09 09:14:22.356: D/AndroidRuntime(1204): Shutting down VM
05-09 09:14:22.356: W/dalvikvm(1204): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-09 09:14:22.377: E/AndroidRuntime(1204): FATAL EXCEPTION: main
05-09 09:14:22.377: E/AndroidRuntime(1204): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxm.view.checkbox/com.xxm.view.checkbox.MainActivity}: java.lang.NullPointerException
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.os.Looper.loop(Looper.java:137)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-09 09:14:22.377: E/AndroidRuntime(1204): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 09:14:22.377: E/AndroidRuntime(1204): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 09:14:22.377: E/AndroidRuntime(1204): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-09 09:14:22.377: E/AndroidRuntime(1204): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-09 09:14:22.377: E/AndroidRuntime(1204): at dalvik.system.NativeStart.main(Native Method)
05-09 09:14:22.377: E/AndroidRuntime(1204): Caused by: java.lang.NullPointerException
05-09 09:14:22.377: E/AndroidRuntime(1204): at com.xxm.view.checkbox.MainActivity.onCreate(MainActivity.java:19)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.Activity.performCreate(Activity.java:5104)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-09 09:14:22.377: E/AndroidRuntime(1204): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-09 09:14:22.377: E/AndroidRuntime(1204): ... 11 more
05-09 09:19:22.476: I/Process(1204): Sending signal. PID: 1204 SIG: 9