Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException when changing android:name value
    primarykey
    data
    text
    <p>In an Android project I needed a way to retrieve a string value not from a Context but from a static method.</p> <p>For this, I've implemented the solution <a href="https://stackoverflow.com/questions/4391720/how-can-i-get-a-esource-content-from-a-static-context">How can I get a resource content from a static context?</a> and I've added to the application tag the android:name attribute: </p> <pre><code>&lt;application android:label="@string/app_name" android:allowBackup="true" android:name=".App"&gt; </code></pre> <p>Now, the application starts, but throws a NullPointerException when executing the following line of code in the OnCreate() of a secondary page:</p> <pre><code>findViewById(R.layout.level).setDrawingCacheEnabled(true); </code></pre> <p>The important part is <code>R.layout.level</code> ("level" is the name of the document that describes the page, level.xml), this object seems to be null now. Here the stack trace:</p> <pre><code>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 </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload