Getting TypeNotPresentException followed by ClassNotFoundException or NoClassDefFoundError on All android versions except android L
E

1

10

I am getting very interesting bug in one of my apps. My app is working fine on android L, But as soon as i try to run it on other android versions, I am getting ClassNotFoundException or NoClassDefFoundError while trying to call web services using Retrofit, even though all those classes are existing and working fine on my android L device. I don't know what's happening right now, app is running in other versions as long as i don't make a Network Request but as soon as i go for Network Request, it gives me either ClassNotFoundException or NoClassDefFoundError. Also I am using Android Studio, so if someone has faced this kind of issue earlier, then please help, i am in severe need.

NOTE : App is working fine on Android L and also classes in which i am getting ClassNotFoundException or NoClassDefFoundError are not version specific i.e it was not like that they are supported in android L or so. All classes in which i am getting these errors are general custom/model classes and has no link with the higher android versions or something.

And these are my Logcat errors

This is the exception while hitting login api

java.lang.TypeNotPresentException: Type com.codebrew.embazaar.pojo.UserLoginPojo not present
            at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:63)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.Types.getTypeArray(Types.java:50)
            at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
            at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
            at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
            at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
            at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
            at $Proxy0.userLogin(Native Method)
            at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
            at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
            at android.view.View.performClick(View.java:4748)
            at android.view.View$PerformClick.run(View.java:19535)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5679)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: com.codebrew.embazaar.pojo.UserLoginPojo
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:61)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.Types.getTypeArray(Types.java:50)
            at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
            at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
            at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
            at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
            at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
            at $Proxy0.userLogin(Native Method)
            at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
            at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
            at android.view.View.performClick(View.java:4748)
            at android.view.View$PerformClick.run(View.java:19535)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5679)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NoClassDefFoundError: com/codebrew/embazaar/pojo/UserLoginPojo
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:61)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.Types.getTypeArray(Types.java:50)
            at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
            at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
            at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
            at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
            at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
            at $Proxy0.userLogin(Native Method)
            at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
            at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
            at android.view.View.performClick(View.java:4748)
            at android.view.View$PerformClick.run(View.java:19535)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5679)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.codebrew.embazaar.pojo.UserLoginPojo" on path: DexPathList[[zip file "/data/app/com.codebrew.embazaar-11.apk"],nativeLibraryDirectories=[/data/app-lib/com.codebrew.embazaar-11, /vendor/lib, /system/lib]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:251)
            at libcore.reflect.ParameterizedTypeImpl.getRawType(ParameterizedTypeImpl.java:61)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:72)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.ParameterizedTypeImpl.getResolvedType(ParameterizedTypeImpl.java:71)
            at libcore.reflect.ListOfTypes.resolveTypes(ListOfTypes.java:70)
            at libcore.reflect.ListOfTypes.getResolvedTypes(ListOfTypes.java:55)
            at libcore.reflect.Types.getTypeArray(Types.java:50)
            at java.lang.reflect.Method.getGenericParameterTypes(Method.java:216)
            at retrofit.RestMethodInfo.parseResponseType(RestMethodInfo.java:250)
            at retrofit.RestMethodInfo.<init>(RestMethodInfo.java:97)
            at retrofit.RestAdapter.getMethodInfo(RestAdapter.java:213)
            at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:236)
            at $Proxy0.userLogin(Native Method)
            at com.codebrew.embazaar.MainActivity.loginUser(MainActivity.java:529)
            at com.codebrew.embazaar.MainActivity.onClick(MainActivity.java:324)
            at android.view.View.performClick(View.java:4748)
            at android.view.View$PerformClick.run(View.java:19535)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5679)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)

and this one i am getting while hitting forgot password network request

java.lang.NoClassDefFoundError: com.codebrew.embazaar.MainActivity$7$1
            at com.codebrew.embazaar.MainActivity$7.onClick(MainActivity.java:392)
            at android.view.View.performClick(View.java:4748)
            at android.view.View$PerformClick.run(View.java:19535)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5679)
            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:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)

**IMPORTANT: As I debugged my code, am getting TypeNotPresentException which is an unchecked exception followed by these ClassNotFoundException or NoClassDefFoundError. I am mentioning this here because i think may be this thing can make some clarity about my question/problem.

Here is my MainActivity CommonPojo and gradle file

Elisabeth answered 27/2, 2015 at 4:21 Comment(14)
I know those errors, what are the super classes of com.codebrew.embazaar.MainActivity? Some class is missing e.g. you missed the compat library.Carmelinacarmelita
you mean to say the super class?? My MainActivity class is extending Activity ClassElisabeth
I think you might be using classes that are introduced in API 21. Like Cards, Recycler view. Try using compat library to support prvious versions. developer.android.com/training/material/compatibility.htmlUnperforated
no i am not using any of API 21 classes as i already mentioned in my questionElisabeth
You might want to post the RestMethodInfo.java file or say where you are fetching it from (didn't find it at github.com/square/retrofit/tree/master/retrofit/src/main/java/…)Plectognath
i am using gradle dependencies for retrofit i.e com.squareup.retrofit:retrofit:1.9.0 . this might contain that RestMethodInfo class and i don't think this class has nothing to do here since everytime am getting different exceptionElisabeth
You should try your luck in Retrofit's official place of bugs/issues here. I'd recommend, however, that you post your code which causes the crashes and any other helpful data like manifest, etc.Masterly
Can you provide an SSCCE that we can pull and play with?Smashup
Sorry.. But actually the problem is when i try by deleting all other Activities, Fragments involved in my project and keeping just MainActivity, then this same code works for me. But as soon as i add the Activities/Fragments, result is same so I don't think providing SSCCE will solve anything as i have already tried thisElisabeth
Can you isolate this issue into a SSCCE?Smashup
that is what i was saying a SSCCE is working for me but not the whole projectElisabeth
posting the whole project is not an option, right?Smashup
hmmm.. I can't do that :(Elisabeth
Can you please post your gradle file?Socha
I
7

This is because you have

multiDexEnabled = true

on your gradle file.

When you enable multidex, you have to make sure that all the classes.dex files are loaded when your application starts. Otherwise it will fail loading classes that is not in the first classes.dex file.

This is not needed in Android L, since it supports loading multiple dex files on startup, not only one.

In order to accomplish this, you can try one of the following:

  • remove multiDexEnabled = true, but you may exceed the 65K method limit.
  • follow the instructions on https://developer.android.com/tools/building/multidex.html, specifically adding the

    compile 'com.android.support:multidex:1.0.0'
    

    dependency, and making your application object inherit or start at MultiDexApplication.

Icelandic answered 4/3, 2015 at 12:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.