07-05 21:13:30.063 7647-7647/root.fazerumsom E/AndroIDRuntime﹕ FATAL EXCEPTION: mainProcess: root.fazerumsom,PID: 7647java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{root.fazerumsom/root.fazerumsom.MainActivity}: java.lang.NullPointerException at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2110) at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at androID.app.ActivityThread.access0(ActivityThread.java:135) at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at androID.os.Handler.dispatchMessage(Handler.java:102) at androID.os.Looper.loop(Looper.java:136) at androID.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at androID.content.Contextwrapper.getResources(Contextwrapper.java:89) at androID.vIEw.ContextthemeWrapper.getResources(ContextthemeWrapper.java:78) at root.fazerumsom.MainActivity.<init>(MainActivity.java:31) at java.lang.class.newInstanceImpl(Native Method) at java.lang.class.newInstance(Class.java:1208) at androID.app.Instrumentation.newActivity(Instrumentation.java:1061) at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2101)at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)at androID.app.ActivityThread.access0(ActivityThread.java:135)at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)at androID.os.Handler.dispatchMessage(Handler.java:102)at androID.os.Looper.loop(Looper.java:136)at androID.app.ActivityThread.main(ActivityThread.java:5001)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:515)at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:601)at dalvik.system.NativeStart.main(Native Method)解决方法 您正在从字段初始值设定项中调用getResources().就像是
private String mStr = getResources().getString(...);
(或使用drawables或其他类型的资源).
这是无效的,因为尚未设置Context.在onCreate()方法中移动此赋值.
总结以上是内存溢出为你收集整理的android – ContextWrapper.getResources()中的NullPointerException全部内容,希望文章能够帮你解决android – ContextWrapper.getResources()中的NullPointerException所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)