为了账号安全,请及时绑定邮箱和手机立即绑定

到底哪里错了?why错了?

		PrintWriter out = response.getWriter();
		Result result = new Result();

		result.setResult(1);
		
		List<Person> personlist = new ArrayList<Person>();
		Person person = new Person();
		person.setAge(24);
		person.setName("hehe");
		person.setUrl("dgfye");
		List<SchoolInfo> schoolInfolist = new ArrayList<SchoolInfo>();
		SchoolInfo schoolinfo1 = new SchoolInfo();
		schoolinfo1.setSchoolname("清华");
		SchoolInfo schoolinfo2 = new SchoolInfo();
		schoolinfo2.setSchoolname("郑大");
		schoolInfolist.add(schoolinfo1);
		schoolInfolist.add(schoolinfo2);
		person.setList(schoolInfolist);
		personlist.add(person);

		Person person1 = new Person();
		person1.setAge(24);
		person1.setName("Bean");
		person1.setUrl("dgfye");
		List<SchoolInfo> schoolInfolist1 = new ArrayList<SchoolInfo>();
		SchoolInfo schoolinfo3 = new SchoolInfo();
		schoolinfo3.setSchoolname("人大");
		SchoolInfo schoolinfo4 = new SchoolInfo();
		schoolinfo4.setSchoolname("北大");
		schoolInfolist1.add(schoolinfo3);
		schoolInfolist1.add(schoolinfo4);
		person1.setList(schoolInfolist1);
		personlist.add(person1);
		
		result.setList(personlist);

		
		Gson gson = new Gson();
		System.out.println(gson.toJson(result));
		out.println(gson.toJson(result));

代码没报错,运行时错了,如下:

十月 20, 2015 10:27:53 上午 org.apache.catalina.core.StandardWrapperValve invoke

严重: Servlet.service() for servlet [bean.json.servlet.BeanJson] in context with path [/BeanJsonPro] threw exception [Servlet execution threw an exception] with root cause

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

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1320)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1173)

at bean.json.servlet.BeanJson.doPost(BeanJson.java:90)

at bean.json.servlet.BeanJson.doGet(BeanJson.java:42)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:534)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)

at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:277)

at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2381)

at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2370)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)


正在回答

3 回答

我觉得是因为你以导入external jar的形式引入gson的,编译导出的时候没有一起导出到项目中,所以执行会报找不到类定义的错误。

你试试将gson-2.2.4.jar包放在WebContent->WEB-INF->lib下,会自动编译到Web App Library中。

1 回复 有任何疑惑可以回复我~
#1

SymphonyZhang

完美解决问题,感谢,感谢。太久没碰J2EE什么都不记得了。。。
2015-12-01 回复 有任何疑惑可以回复我~
#2

慕姐6825620 提问者

非常感谢!我试试
2015-12-14 回复 有任何疑惑可以回复我~

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

这是错误原因(为啥?我也不知道-_-)

0 回复 有任何疑惑可以回复我~
#1

慕姐6825620 提问者

正在头疼中。。。。。。。。。。
2015-10-21 回复 有任何疑惑可以回复我~
#2

化龙贝 回复 慕姐6825620 提问者

缺少jar包吗?
2015-10-21 回复 有任何疑惑可以回复我~
#3

qq__2824

你们解决了么,java.lang.ClassNotFoundException: com.google.gson.Gson
2016-05-01 回复 有任何疑惑可以回复我~

只是我Text.java运行的结果

{"result":1,"list":[{"name":"hehe","age":24,"url":"dgfye","list":[{"schoolname":"清华"},{"schoolname":"郑大"}]},{"name":"Bean","age":24,"url":"dgfye","list":[{"schoolname":"人大"},{"schoolname":"北大"}]}]}


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android中的Http通信
  • 参与学习       64671    人
  • 解答问题       306    个

了解Android-http网络编程应用,常见忘了请求相关应用

进入课程

到底哪里错了?why错了?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信