Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gson TypeToken classNotFoundException

Tags:

java

gson

tomcat

webserver: tomcat

web framework: spring3

I use gson-2.3.1

follow error log

java.lang.ClassNotFoundException: com.mysite.chart.**ChartCtrl$2**
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
**at com.mysite.chart.ChartCtrl.msyData(ChartCtrl.java:278)**
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)

and ChartCtrl 278 line is follow

Type objType = new TypeToken<ArrayList<HashMap<String, Object>>>(){}.getType();

How can I solve this problem.

like image 277
리루스 Avatar asked Dec 05 '25 07:12

리루스


1 Answers

I also faced this issue, in my case I was importing the wrong class which somehow was available in the classpath for IDE but not on runtime.

Replace the below one:

import com.google.common.reflect.TypeToken;

With this one:

import com.google.gson.reflect.TypeToken;
like image 151
Prateek Jain Avatar answered Dec 07 '25 21:12

Prateek Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!