0

When i run my app on my phone with eclipse i have no problems at all but when i sign my app then install it on my device i get an ClassNotFoundException.

The class android can't find is a static context class which extends Application:

public class ProjectContext extends Application{

    private static Context context;

    public void onCreate() {
        super.onCreate();
        ProjectContext.context = getApplicationContext();
    }

    public static Context getAppContext() {
        return ProjectContext.context;
    }
}

STACKTRACE

java.lang.RuntimeException: Unable to instantiate application Context: java.lang.ClassNotFoundException: Didn't find class ".Context" on path: DexPathList[[zip file "/data/app/n-1.apk"],nativeLibraryDirectories=[/data/app-lib/app-1, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:514)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4446)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
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:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "Context" on path: DexPathList[[zip file "/data/app/app-1.apk"],nativeLibraryDirectories=[/data/app-lib/app-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:975)
at android.app.LoadedApk.makeApplication(LoadedApk.java:509)
... 11 more

I don't know what is wrong. I hope someone can help me.

EDIT:

private static SharedPreferences getData = PreferenceManager.getDefaultSharedPreferences(NzbManagerContext.getAppContext());
Timmeeh93
  • 223
  • 1
  • 4
  • 14
  • 1
    Show where you declare the type `NzbManagerContext` – Vince Nov 13 '14 at 15:12
  • You need to instantiate the NzbManagerContext class.And then only you can able to assign the context to that class object... – Srinivasan Nov 13 '14 at 15:13
  • I just use it to get the context for my sharedpreference, see edited post – Timmeeh93 Nov 13 '14 at 15:15
  • 1
    I still dont see a class, interface or enum named `NzbManagerContext`. As far as I know (and as your stack trace tells you) it doesn't exist. Show us where you declared this type, cause its definitely not in any android APIs – Vince Nov 13 '14 at 15:19
  • I have followed this way: http://stackoverflow.com/questions/2002288/static-way-to-get-context-on-android so i suppose i dont have to declare it or am i wrong? – Timmeeh93 Nov 13 '14 at 15:42
  • Please check in the sample they used, MyApplication.context = getApplicationContext(); If so you have to replace ProjectContext.context = getApplicationContext(); – Srinivasan Nov 13 '14 at 15:44
  • But it's completly strange, if i run it directly from Eclipse it just works. Only if i create an APK first i get a ClassNotFoundException. – Timmeeh93 Nov 13 '14 at 15:49
  • 1
    Fixed it by using the answer from Tadas Valaitis http://stackoverflow.com/questions/11597707/it-got-the-java-lang-classnotfoundexception-error-when-run-the-export-apk – Timmeeh93 Nov 13 '14 at 16:13

0 Answers0