I am receiving a 'Unable to instantiate activity' error when I try to load up my program. One thing that baffles me is the exact same code works on my older PC. I just built a new one with new eclipse / android SDK / etc. I have both machines running the same code, one works fine and the other gives this error.
Any thoughts?
Edit: One thing I notice in the stack is
Caused by: java.lang.ClassNotFoundException: com.voldaran.puzzle.graBLOX.PopActivity in loader dalvik.system.PathClassLoader[/data/app/com.voldaran.puzzle.graBLOX-2.apk]
It lists graBLOX-2.apk . Why is it using '-2.apk'?
When I manually reproduce this error on the working machine, it does not display that last []'d part.
Android Manifest
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".PopActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:finishOnTaskLaunch="true"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Stack
04-21 17:33:42.284: E/AndroidRuntime(4045): FATAL EXCEPTION: main
04-21 17:33:42.284: E/AndroidRuntime(4045): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.voldaran.puzzle.graBLOX/com.voldaran.puzzle.graBLOX.PopActivity}: java.lang.ClassNotFoundException: com.voldaran.puzzle.graBLOX.PopActivity in loader dalvik.system.PathClassLoader[/data/app/com.voldaran.puzzle.graBLOX-2.apk]
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.os.Looper.loop(Looper.java:130)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-21 17:33:42.284: E/AndroidRuntime(4045): at java.lang.reflect.Method.invokeNative(Native Method)
04-21 17:33:42.284: E/AndroidRuntime(4045): at java.lang.reflect.Method.invoke(Method.java:507)
04-21 17:33:42.284: E/AndroidRuntime(4045): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-21 17:33:42.284: E/AndroidRuntime(4045): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-21 17:33:42.284: E/AndroidRuntime(4045): at dalvik.system.NativeStart.main(Native Method)
04-21 17:33:42.284: E/AndroidRuntime(4045): Caused by: java.lang.ClassNotFoundException: com.voldaran.puzzle.graBLOX.PopActivity in loader dalvik.system.PathClassLoader[/data/app/com.voldaran.puzzle.graBLOX-2.apk]
04-21 17:33:42.284: E/AndroidRuntime(4045): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
04-21 17:33:42.284: E/AndroidRuntime(4045): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
04-21 17:33:42.284: E/AndroidRuntime(4045): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-21 17:33:42.284: E/AndroidRuntime(4045): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
I was happening pretty much the same situation (project made initially in 32 bit machine, then imported in another 64 bit machine).
In Android projects under Eclipse Juno (64 bit):
Try this. Add this piece of code inside your PopActivity
and call this function from inside its default constructor.
private static void fixClassLoaderIssue()
{
ClassLoader myClassLoader = MyClass.class.getClassLoader();
Thread.currentThread().setContextClassLoader(myClassLoader);
}
I had a similar issue and this fixed it. Now this solution doesnt really answer why the problem exists, but I really couldnt find that out.
For reference check this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With