问题
I am new on Android Development environment so need help from the experts.
java.lang.NoClassDefFoundError: com.google.gson.Gson
Gson library included in project but when calling Gson from a method inside the project getting the error like ths
回答1:
Here are a couple of reasons that this could be happening:
a) The library jar file is not being included
b) The wrong version of the jar file is being included
c) (if you are using maven) Another jar file is pulling in a newer/different version of the jar file
d) Your class path does not include the jar file.
A good starting point is to open the library jar file and see if you can actually see the class file in it. If you are using maven then you should view the dependency tree to see if there are any conflicts using:
mvn dependency:tree -Dverbose
回答2:
- Down load the latest version of gason.jar
- Add the jar of gason to the project[Eclipse: project proprieties => Java Build Path => Libraries =>Add External JARs]
- check the gason.jar in Order and Export
回答3:
This worked for me
java -cp gson.jar: JavaClassFile
Notice the :
after gson.jar
.
回答4:
put the jar file in web-inf/lib,not the lib
回答5:
A couple of reasons for the issue:
- .aar Library: if the code involving Gson is in a .aar that is included in an application project as a library; in this case, the application should also add gson as a dependency
reason: .aar libs do not propagate dependencies transitively
- proguard: wrong proguard rules required by gson, correct rules can be found here
来源:https://stackoverflow.com/questions/22420643/java-lang-noclassdeffounderror-com-google-gson-gson