findViewById返回null,求大神解决。 发现在 findViewById(R.id.eat) 返回null,我不清楚哪里错了,返回了null 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 logcat06-22 11:30:27.610: E/AndroidRuntime(2013): FATAL EXCEPTION: main06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.access$800(ActivityThread.java:135)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.os.Handler.dispatchMessage(Handler.java:102)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.os.Looper.loop(Looper.java:136)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.main(ActivityThread.java:5017)06-22 11:30:27.610: E/AndroidRuntime(2013): at java.lang.reflect.Method.invokeNative(Native Method)06-22 11:30:27.610: E/AndroidRuntime(2013): at java.lang.reflect.Method.invoke(Method.java:515)06-22 11:30:27.610: E/AndroidRuntime(2013): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)06-22 11:30:27.610: E/AndroidRuntime(2013): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)06-22 11:30:27.610: E/AndroidRuntime(2013): at dalvik.system.NativeStart.main(Native Method)06-22 11:30:27.610: E/AndroidRuntime(2013): Caused by: java.lang.NullPointerException06-22 11:30:27.610: E/AndroidRuntime(2013): at com.hipad.checkboxtext.MainActivity.onCreate(MainActivity.java:38)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.Activity.performCreate(Activity.java:5231)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)06-22 11:30:27.610: E/AndroidRuntime(2013): ... 11 more 你实例化控件错了地方写在 /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); eat = (CheckBox)rootView .findViewById(R.id.eat); System.out.println(R.id.eat+"..."); sleep = (CheckBox)rootView.findViewById(R.id.sleep); all = (CheckBox)rootView.findViewById(R.id.all); return rootView; } }中的onCreateViewl里面 你控件写在fragment_main.xml 加载页面却是activity_main.xml 当然报null啦 3#正解!注意PlaceholderFragment ,这是跟之前版本的不同! android怎么屏蔽状态栏下拉? 请教异常的原因No Activity found to handle Intent { act=android.intent.action.VIEW dat=w 求助播放本地视频资源 我发个问题,求高手进! android中播放视频 使用getNativeSurface FindClass 出错 android开发之百度地图api应用 求助关于android studio 怎样给Fragment中的按钮添加点击事件? webapp图标的左右滑动 帮我看看,下面这个软件需要会那些语言,谢谢了 大神请进 最新百分百获得100QB话费活动!!!
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.os.Handler.dispatchMessage(Handler.java:102)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.os.Looper.loop(Looper.java:136)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.main(ActivityThread.java:5017)
06-22 11:30:27.610: E/AndroidRuntime(2013): at java.lang.reflect.Method.invokeNative(Native Method)
06-22 11:30:27.610: E/AndroidRuntime(2013): at java.lang.reflect.Method.invoke(Method.java:515)
06-22 11:30:27.610: E/AndroidRuntime(2013): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
06-22 11:30:27.610: E/AndroidRuntime(2013): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
06-22 11:30:27.610: E/AndroidRuntime(2013): at dalvik.system.NativeStart.main(Native Method)
06-22 11:30:27.610: E/AndroidRuntime(2013): Caused by: java.lang.NullPointerException
06-22 11:30:27.610: E/AndroidRuntime(2013): at com.hipad.checkboxtext.MainActivity.onCreate(MainActivity.java:38)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.Activity.performCreate(Activity.java:5231)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-22 11:30:27.610: E/AndroidRuntime(2013): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
06-22 11:30:27.610: E/AndroidRuntime(2013): ... 11 more
写在 /**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
eat = (CheckBox)rootView .findViewById(R.id.eat);
System.out.println(R.id.eat+"...");
sleep = (CheckBox)rootView.findViewById(R.id.sleep);
all = (CheckBox)rootView.findViewById(R.id.all);
return rootView;
}
}中的onCreateViewl里面