我是Android的开发新手,我不知道如何阅读logcat。我正在尝试开发android webview应用程序,但遇到了这些错误。
E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Process: com.tech.neucial, PID: 25698
E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tech.neucial/com.tech.neucial.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setHomeButtonEnabled(boolean)' on a null object reference
E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2329)
E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
E/AndroidRuntime: at android.app.ActivityThread.access$900(ActivityThread.java:147)
E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5256)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setHomeButtonEnabled(boolean)' on a null object reference
E/AndroidRuntime: at com.tech.neucial.MainActivity.onCreate(MainActivity.java:39)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5933)
E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
E/AndroidRuntime: ... 10 more
我已经尽力了解但没有决心。 这是源代码。 https://www.mediafire.com/?28yu5r0y7o19383
PS:我正在上传整个源代码,因为我不知道哪个文件导致了这个问题,并且有5个或6个文件我无法在这里粘贴。
感谢。
答案 0 :(得分:0)
在MainActivity的onCreate中使用 getSupportActionBar()方法而不是getActionBar()