问题描述
我使用的是Android工作室,一切都准备好,直到我更新我的 SDK
来API级别21,也更新支持库。在更新我没有得到 NullPointerException异常
,但更新后的 SDK
获得 NullPointerException异常
为 getActionBar()
在运行时不改变code或任何东西单行。请帮帮我,一件事,我在采用Android Studio的初学者。
日志:
07-09 13:46:12.138 25209-25209 / com.oi.abc E / AndroidRuntime:致命异常:主要
java.lang.RuntimeException的:无法启动的活动ComponentInfo {com.oi.abc / com.oi.abc.HomeScreenActivity}:显示java.lang.NullPointerException
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
在android.app.ActivityThread.access $ 700(ActivityThread.java:140)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1237)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4921)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1027)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
在dalvik.system.NativeStart.main(本机方法)
显示java.lang.NullPointerException:产生的原因
在com.oi.abc.NavigationDrawerExpandableListviewClass.initializeScreen(NavigationDrawerExpandableListviewClass.java:148)
在com.oi.abc.NavigationDrawerExpandableListviewClass.onCreate(NavigationDrawerExpandableListviewClass.java:71)
在com.oi.abc.HomeScreenActivity.onCreate(HomeScreenActivity.java:47)
在android.app.Activity.performCreate(Activity.java:5206)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
在android.app.ActivityThread.access $ 700(ActivityThread.java:140)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1237)
在android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:4921)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1027)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
在dalvik.system.NativeStart.main(本机方法)
我encoutner这样那样的问题,但没有看到你的$ C $词不能说much.Here 2种方式可能发生,有我想没有其他ways.First是,更新后你现在有app.v7.widget.ActionBar,你有app.widget.Actionbar,所以在这里它是如何去,如果你的可操作的导入为第一个我上面提到的,使用此
getSupportActionBar()
但如果进口的第二个你应该只使用
getActionBar()
主要是你可能会得到空指针,因为我可能已经猜到进口可操作的是错误的,你可能想使用it.Thats支持库的新版本和Android的软件开发工具包可惜我没有encouter几次到这一点我的第一选择问题。
I'm using Android Studio, everything was going good until I update my SDK
to API level 21 and also update Support Library.Before Updating I was not getting NullPointerException
but after updating SDK
getting NullPointerException
for getActionBar()
at runtime without changing any single line of code or anything.Please help me, one more thing I'm beginner in using Android Studio.
Log:
07-09 13:46:12.138 25209-25209/com.oi.abc E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oi.abc/com.oi.abc.HomeScreenActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.oi.abc.NavigationDrawerExpandableListviewClass.initializeScreen(NavigationDrawerExpandableListviewClass.java:148)
at com.oi.abc.NavigationDrawerExpandableListviewClass.onCreate(NavigationDrawerExpandableListviewClass.java:71)
at com.oi.abc.HomeScreenActivity.onCreate(HomeScreenActivity.java:47)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
I encoutner such kind of problems but without seeing your code i can't say much.Here 2 ways which might happen and there are i guess no other ways.First is that after update you now have app.v7.widget.ActionBar and you have app.widget.Actionbar,so here how it goes,if your actionable is imported as FIRST one i mentioned above,use this
getSupportActionBar()
however if its imported the second one you should uses only
getActionBar()
Mostly your might get null pointer as i might guess the imported actionable is wrong one and you might want to uses my first option of it.Thats the new revision of supports library and sdks of android unfortunately i did encouter couple times to this issue.
这篇关于获得NullPointerException异常的getActionBar更新SDK后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!