java.lang.NoClassDefFoundError: com.google.gson.Gson

拜拜、爱过 提交于 2021-02-10 12:28:47

问题


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:


  1. Down load the latest version of gason.jar
  2. Add the jar of gason to the project[Eclipse: project proprieties => Java Build Path => Libraries =>Add External JARs]
  3. 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:

  1. .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

  1. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!