本文介绍了preferenceFragment编译,但我的程序不起作用。有什么事 ?异常code是这里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
11月3日至四日:09:41.524:E / AndroidRuntime(943):致命异常:主要
11月3日至四日:09:41.524:E / AndroidRuntime(943):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.otobusumnerede / com.otobusumnerede.AyarlarActivity}:显示java.lang.NullPointerException
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.os.Handler.dispatchMessage(Handler.java:99)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.os.Looper.loop(Looper.java:137)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.ActivityThread.main(ActivityThread.java:5041)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在java.lang.reflect.Method.invokeNative(本机方法)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在java.lang.reflect.Method.invoke(Method.java:511)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在dalvik.system.NativeStart.main(本机方法)
11月3日至四日:09:41.524:E / AndroidRuntime(943):致:显示java.lang.NullPointerException
11月3日至四日:09:41.524:E / AndroidRuntime(943):在com.otobusumnerede.AyarlarActivity.onCreate(AyarlarActivity.java:24)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.Activity.performCreate(Activity.java:5104)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11月3日至四日:09:41.524:E / AndroidRuntime(943):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11月3日至四日:09:41.524:E / AndroidRuntime(943):11 ...更多
11月3日至四日:24:14.452:E /跟踪(1311):错误打开跟踪文件:没有这样的文件或目录(2)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):致命异常:主要
11月3日至四日:24:44.843:E / AndroidRuntime(1311):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.otobusumnerede / com.otobusumnerede.AyarlarActivity}:显示java.lang.NullPointerException
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.ActivityThread.access $ 600(ActivityThread.java:141)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1234)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.os.Handler.dispatchMessage(Handler.java:99)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.os.Looper.loop(Looper.java:137)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.ActivityThread.main(ActivityThread.java:5041)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在java.lang.reflect.Method.invokeNative(本机方法)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在java.lang.reflect.Method.invoke(Method.java:511)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在dalvik.system.NativeStart.main(本机方法)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):因:显示java.lang.NullPointerException
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在com.otobusumnerede.AyarlarActivity.onCreate(AyarlarActivity.java:25)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.Activity.performCreate(Activity.java:5104)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11月3日至四日:24:44.843:E / AndroidRuntime(1311):11 ...更多
解决方案
如果你可以从你的活动复制文本并粘贴,或code的ATLEAST贴线25号,它更容易帮助您。
通过走出去,因为它是在你的活动这么早,检查的onCreate()
第一
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.yourlayoutxml);
ImageView的=(ImageView的)findViewById(R.id.yourimageviewid); //只是一个例子
- 确保调用
的setContentView()
之前的任何findViewById
- 检查您是否已经声明,初始化的变量正确
- 如果是这样,寻找那些可能是空值
03-04 11:09:41.524: E/AndroidRuntime(943): FATAL EXCEPTION: main
03-04 11:09:41.524: E/AndroidRuntime(943): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.otobusumnerede/com.otobusumnerede.AyarlarActivity}: java.lang.NullPointerException
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.os.Looper.loop(Looper.java:137)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 11:09:41.524: E/AndroidRuntime(943): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 11:09:41.524: E/AndroidRuntime(943): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 11:09:41.524: E/AndroidRuntime(943): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 11:09:41.524: E/AndroidRuntime(943): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 11:09:41.524: E/AndroidRuntime(943): at dalvik.system.NativeStart.main(Native Method)
03-04 11:09:41.524: E/AndroidRuntime(943): Caused by: java.lang.NullPointerException
03-04 11:09:41.524: E/AndroidRuntime(943): at com.otobusumnerede.AyarlarActivity.onCreate(AyarlarActivity.java:24)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.Activity.performCreate(Activity.java:5104)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 11:09:41.524: E/AndroidRuntime(943): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 11:09:41.524: E/AndroidRuntime(943): ... 11 more
03-04 11:24:14.452: E/Trace(1311): error opening trace file: No such file or directory (2)
03-04 11:24:44.843: E/AndroidRuntime(1311): FATAL EXCEPTION: main
03-04 11:24:44.843: E/AndroidRuntime(1311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.otobusumnerede/com.otobusumnerede.AyarlarActivity}: java.lang.NullPointerException
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.os.Handler.dispatchMessage(Handler.java:99)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.os.Looper.loop(Looper.java:137)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.main(ActivityThread.java:5041)
03-04 11:24:44.843: E/AndroidRuntime(1311): at java.lang.reflect.Method.invokeNative(Native Method)
03-04 11:24:44.843: E/AndroidRuntime(1311): at java.lang.reflect.Method.invoke(Method.java:511)
03-04 11:24:44.843: E/AndroidRuntime(1311): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-04 11:24:44.843: E/AndroidRuntime(1311): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-04 11:24:44.843: E/AndroidRuntime(1311): at dalvik.system.NativeStart.main(Native Method)
03-04 11:24:44.843: E/AndroidRuntime(1311): Caused by: java.lang.NullPointerException
03-04 11:24:44.843: E/AndroidRuntime(1311): at com.otobusumnerede.AyarlarActivity.onCreate(AyarlarActivity.java:25)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.Activity.performCreate(Activity.java:5104)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-04 11:24:44.843: E/AndroidRuntime(1311): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-04 11:24:44.843: E/AndroidRuntime(1311): ... 11 more
解决方案
If you can copy text from your activity and paste it, or atleast paste line no.25 of your code, its easier to help you.
Going by as it is so early in your activity, check onCreate()
first
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayoutxml);
imageView = (ImageView) findViewById(R.id.yourimageviewid); //just an example
- make sure to call
setContentView()
before anyfindViewById
- check if you have declared, initialized your variables properly
- if so, look for a value that could be null
这篇关于preferenceFragment编译,但我的程序不起作用。有什么事 ?异常code是这里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!