My code was working perfectly before but now it is throwing out an exception,
The code :
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonElement jsonElement = JsonParser.parseString(resultJsonString);
and the exception in the line JsonElement jsonElement = JsonParser.parseString(resultJsonString);
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method parseString(String) is undefined for the type JsonParser
Any hints to why this is happening? It was working fine till yesterday!
This looks more like you've named your own class the same way as the Gson JsonParser
class. So the compiler resolves JsonParser
to your own class (your.package.JsonParser
) and not to the Gson JsonParser (com.google.gson.JsonParser)
. You may want to rename your class or use com.google.gson.JsonParser
instead of JsonParser
each time you want to refer to this class.
Another possibility is that the Gson
library that you're using might be older than version 2.8.6
. If this is the case, you've to upgrade your Gson
lib. The static method JsonParser.parseString
is added in version 2.8.6
. Checkout the change log.
For Maven, use:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
For Gradle, use:
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
For SBT, use:
libraryDependencies += "com.google.code.gson" % "gson" % "2.8.6"
For Ivy, use:
<dependency org="com.google.code.gson" name="gson" rev="2.8.6"/>
For Grape, use:
@Grapes(
@Grab(group='com.google.code.gson', module='gson', version='2.8.6')
)
For Leiningen, use:
[com.google.code.gson/gson "2.8.6"]
For Buildr, use:
'com.google.code.gson:gson:jar:2.8.6'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With