9

I get the following exception every time I reinstall my through eclipse. It happens every time I reinstall an app that is currently in the foreground.

I expect that this error is only happening during development because I cause an uninstallation of a running app through Eclipse.

Has anybody seen this error on user phones?

This started happening for me as I switched to a Galaxy Nexus with ICS.

02-22 11:31:07.098: E/AndroidRuntime(479): FATAL EXCEPTION: main
02-22 11:31:07.098: E/AndroidRuntime(479): java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.LoadedApk.makeApplication(LoadedApk.java:466)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3260)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.ActivityThread.access$2200(ActivityThread.java:117)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:969)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.os.Looper.loop(Looper.java:123)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-22 11:31:07.098: E/AndroidRuntime(479):  at java.lang.reflect.Method.invokeNative(Native Method)
02-22 11:31:07.098: E/AndroidRuntime(479):  at java.lang.reflect.Method.invoke(Method.java:507)
02-22 11:31:07.098: E/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-22 11:31:07.098: E/AndroidRuntime(479):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-22 11:31:07.098: E/AndroidRuntime(479):  at dalvik.system.NativeStart.main(Native Method)
02-22 11:31:07.098: E/AndroidRuntime(479): Caused by: java.lang.NullPointerException
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:346)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.LoadedApk.getClassLoader(LoadedApk.java:291)
02-22 11:31:07.098: E/AndroidRuntime(479):  at android.app.LoadedApk.makeApplication(LoadedApk.java:458)
02-22 11:31:07.098: E/AndroidRuntime(479):  ... 11 more

In the above logs i didn't find any thing related to my application. But still it's crashing.

Can any one tell me what's the reason for this? Is this a bug in Ice Cream Sandwich of on the Galaxy Nexus?

Swati Garg
  • 995
  • 1
  • 10
  • 21
Sankar
  • 1,685
  • 2
  • 16
  • 27
  • 5
    can you upload your code please ? – Lucifer Feb 22 '12 at 07:00
  • why to downvote for this, there is nothing to do with my application in logs it's showing NullPointer related to android.app.application if you guys want i posted my manifest also with application tag. – Sankar Feb 22 '12 at 07:18
  • You are being downvoted because you haven't asked anything really. – rf43 Feb 22 '12 at 07:25
  • @Android there is no related code. This error happens while the App is reinstalling. – Janusz Mar 22 '12 at 12:05
  • The error occurs for me too since I develop on a Galaxy Nexus. What phone and Android Version are you working with? – Janusz Mar 22 '12 at 12:06
  • I also found an issue in the Android Issue tracker. Only 3 people starred it yet. If you also experience this error please star the issue: http://code.google.com/p/android/issues/detail?id=25869 – Janusz Mar 22 '12 at 12:13
  • 1
    You say this happens when you reinstall via Eclipse. After this crash, can you start the application normally by selecting it from the list of installed applications? Or does it always crash? – David Wasser Mar 22 '12 at 14:17
  • 1
    @DavidWasser No, It's not crashing. I am able to start and use this by selecting it from installed apps. – Sankar Mar 22 '12 at 14:24
  • not sure, but worth a check mabye you will see something: http://stackoverflow.com/questions/7957991/android-sqlite-openorcreatedatabase-nullpointerexception – Nadav Ben-Gal Mar 28 '12 at 16:09

3 Answers3

1

i got this problem when someting in XML is wrong, maybe you just have to regenerate your R.java

Boe-Dev
  • 1,585
  • 2
  • 14
  • 26
0

You have a null pointer on line 346 in the initializeJavaContextClassLoader method.

02-22 11:31:07.098: E/AndroidRuntime(479): at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:346)

Edit

Here is the method from the GrepCode/com.google.android/android/2.3_r1/ android.app.LoadedApk (starting at line 326)

private void initializeJavaContextClassLoader() {
    IPackageManager pm = ActivityThread.getPackageManager();
    android.content.pm.PackageInfo pi;
    try {
        pi = pm.getPackageInfo(mPackageName, 0);
    } catch (RemoteException e) {
        throw new AssertionError(e);
    }
    /*
     * Two possible indications that this package could be
     * sharing its virtual machine with other packages:
     *
     * 1.) the sharedUserId attribute is set in the manifest,
     *     indicating a request to share a VM with other
     *     packages with the same sharedUserId.
     *
     * 2.) the application element of the manifest has an
     *     attribute specifying a non-default process name,
     *     indicating the desire to run in another packages VM.
     */
    boolean sharedUserIdSet = (pi.sharedUserId != null);
    boolean processNameNotDefault =
            (pi.applicationInfo != null &&
            !mPackageName.equals(pi.applicationInfo.processName));
    boolean sharable = (sharedUserIdSet || processNameNotDefault);
    ClassLoader contextClassLoader =
            (sharable)
            ? new WarningContextClassLoader()
    : mClassLoader;
            Thread.currentThread().setContextClassLoader(contextClassLoader);
}

It looks like you might be trying to share a virtual machine with another package.

jnthnjns
  • 8,962
  • 4
  • 42
  • 65
rf43
  • 4,385
  • 3
  • 23
  • 28
  • Ya i know but this LoadedApk.java is system related class what can i do with my code. Is it my emulator problem. – Sankar Feb 22 '12 at 07:32
  • 1
    No it is not your emulator. Yes LoadedApk.java is a system related file but it is something that you are doing to that method. It is your code I can almost guarantee it! – rf43 Feb 22 '12 at 10:46
  • 2
    I didn't use this method any where in my code. This class is used while loading the apk into device then what i did for this in my code. – Sankar Feb 22 '12 at 11:01
  • 7
    @DDoSAttack I always would blame the programmer and not the framework. And it can still be an error in the app setup that causes this error. But the nullpointer Exception is totally out of scope of the programmers reach. Your answer is not helping. – Janusz Mar 22 '12 at 12:07
  • 1
    @Janusz I disagree. As you said it could be an app setup error. This still falls within the reach of the developer. There is no reason that, under normal circumstances, the dev would need to alter the code I posted. I have that there to show where it is failing and why. – rf43 Mar 23 '12 at 15:43
0

I had this problem recently but showing up in IDEA. I had to switch mid-project to Eclipse - ouch! I got no good answers on here an eventually, after I finished the project, I went back to IDEA and tried again. The final solution was to move the project out of my workspace, delete everything except my source and resources, then create a new project from existing sources. I wasted hours trying to figure this out and it might just work for you in Eclipse. Got to be worth a try...

Good luck

Simon
  • 14,407
  • 8
  • 46
  • 61