NullPointerException when changing android:name value
In an Android project I needed a way to retrieve a string value not from a
Context but from a static method.
For this, I've implemented the solution How can I get a resource content
from a static context? and I've added to the application tag the
android:name attribute:
<application android:label="@string/app_name" android:allowBackup="true"
android:name=".App">
Now, the application starts, but throws a NullPointerException when
executing the following line of code in the OnCreate() of a secondary
page:
findViewById(R.layout.level).setDrawingCacheEnabled(true);
The important part is R.layout.level ("level" is the name of the document
that describes the page, level.xml), this object seems to be null now.
Here the stack trace:
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime FATAL
EXCEPTION: main
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.UpMap/com.UpMap.LevelActivity}:
java.lang.NullPointerException
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.app.ActivityThread.access$2300(ActivityThread.java:125)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.os.Handler.dispatchMessage(Handler.java:99)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.os.Looper.loop(Looper.java:123)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.app.ActivityThread.main(ActivityThread.java:4627)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
java.lang.reflect.Method.invokeNative(Native Method)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
java.lang.reflect.Method.invoke(Method.java:521)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
dalvik.system.NativeStart.main(Native Method)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime Caused by:
java.lang.NullPointerException
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
com.UpMap.LevelActivity.onCreate(LevelActivity.java:64)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
23:42:33.255 3550 com.UpMap ERROR AndroidRuntime ... 11 more
How can I fix this? The original solution seems ok for most of the people,
but not for me! Is that something related to the android:name attribute?
No comments:
Post a Comment