Sreejin TV
Sreejin TV

Reputation: 117

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

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

Upvotes: 7

Views: 42831

Answers (5)

hashmap
hashmap

Reputation: 400

This worked for me

java -cp gson.jar: JavaClassFile

Notice the : after gson.jar.

Upvotes: 1

adwait
adwait

Reputation: 41

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

Upvotes: 0

Fahim Faysal
Fahim Faysal

Reputation: 459

  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

Upvotes: 4

well
well

Reputation: 1

put the jar file in web-inf/lib,not the lib

Upvotes: 0

Nick Weedon
Nick Weedon

Reputation: 451

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

Upvotes: 12

Related Questions