急!ssh+json 空指针异常(net.sf.json.JSONException: java.lang.NullPointerException) 5
net.sf.json.JSONException:java.lang.NullPointerExceptionatnet.sf.json.JSONObject._fro...
net.sf.json.JSONException: java.lang.NullPointerException
at net.sf.json.JSONObject._fromBean(JSONObject.java:959)
at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
at net.sf.json.JSONArray._processValue(JSONArray.java:2562)
at net.sf.json.JSONArray.processValue(JSONArray.java:2593)
at net.sf.json.JSONArray.addValue(JSONArray.java:2580)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1084)
at net.sf.json.JSONArray.fromObject(JSONArray.java:147)
at gah.ajaxAction.GetVillageAction.execute(GetVillageAction.java:71)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at gah.service.MuserFilter.doFilter(MuserFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
注:已经从hibernate 那里拿到了数据,这里从打印出来的:viialge222 name=哈哈
这个是action类中主要部分(太长了粘不上),运行到json=JSONArray.fromObject(vs,config);这里就报错了,但vs里是有数据的,都能打印出来
GetVillageForm gvf=(GetVillageForm) form;
if(null!=gvf){
vs=ajaxDao.getVillage(gvf.getDId());
System.out.println("vl="+vs);
Iterator<Village> i=vs.iterator();
while(i.hasNext()){
System.out.println("viialge222 name="+i.next().getAName());
}
JsonConfig config = new JsonConfig();
config.setJsonPropertyFilter(new PropertyFilter()
{
public boolean apply(Object source, String name, Object value) {
System.out.println("village name:"+name);
if(name.equals("district")||name.equals("ccompanies")) {
return true;
} else {
return false;
}
}
});try {
json=JSONArray.fromObject(vs,config);
response.getWriter().write(json.toString());
} catch (Exception e) {
e.printStackTrace(); 展开
at net.sf.json.JSONObject._fromBean(JSONObject.java:959)
at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
at net.sf.json.JSONArray._processValue(JSONArray.java:2562)
at net.sf.json.JSONArray.processValue(JSONArray.java:2593)
at net.sf.json.JSONArray.addValue(JSONArray.java:2580)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1084)
at net.sf.json.JSONArray.fromObject(JSONArray.java:147)
at gah.ajaxAction.GetVillageAction.execute(GetVillageAction.java:71)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at gah.service.MuserFilter.doFilter(MuserFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
注:已经从hibernate 那里拿到了数据,这里从打印出来的:viialge222 name=哈哈
这个是action类中主要部分(太长了粘不上),运行到json=JSONArray.fromObject(vs,config);这里就报错了,但vs里是有数据的,都能打印出来
GetVillageForm gvf=(GetVillageForm) form;
if(null!=gvf){
vs=ajaxDao.getVillage(gvf.getDId());
System.out.println("vl="+vs);
Iterator<Village> i=vs.iterator();
while(i.hasNext()){
System.out.println("viialge222 name="+i.next().getAName());
}
JsonConfig config = new JsonConfig();
config.setJsonPropertyFilter(new PropertyFilter()
{
public boolean apply(Object source, String name, Object value) {
System.out.println("village name:"+name);
if(name.equals("district")||name.equals("ccompanies")) {
return true;
} else {
return false;
}
}
});try {
json=JSONArray.fromObject(vs,config);
response.getWriter().write(json.toString());
} catch (Exception e) {
e.printStackTrace(); 展开
3个回答
展开全部
net.sf.json.JSONException: java.lang.NullPointerException
at net.sf.json.JSONObject._fromBean(JSONObject.java:959)
at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
at net.sf.json.JSONArray._processValue(JSONArray.java:2562)
at net.sf.json.JSONArray.processValue(JSONArray.java:2593)
at net.sf.json.JSONArray.addValue(JSONArray.java:2580)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1084)
at net.sf.json.JSONArray.fromObject(JSONArray.java:147)
at gah.ajaxAction.GetVillageAction.execute(GetVillageAction.java:71)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at gah.service.MuserFilter.doFilter(MuserFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
注:已经从hibernate 那里拿到了数据,这里从打印出来的:viialge222
at net.sf.json.JSONObject._fromBean(JSONObject.java:959)
at net.sf.json.JSONObject.fromObject(JSONObject.java:194)
at net.sf.json.JSONArray._processValue(JSONArray.java:2562)
at net.sf.json.JSONArray.processValue(JSONArray.java:2593)
at net.sf.json.JSONArray.addValue(JSONArray.java:2580)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1084)
at net.sf.json.JSONArray.fromObject(JSONArray.java:147)
at gah.ajaxAction.GetVillageAction.execute(GetVillageAction.java:71)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at gah.service.MuserFilter.doFilter(MuserFilter.java:44)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
注:已经从hibernate 那里拿到了数据,这里从打印出来的:viialge222
展开全部
这只是一个简单的空指针报错
只能看出是 GetVillageAction.java的71行 某个对象执行方法时 由于这个对象是null 才报的错
要更详细的 请把代码贴出来看看
---------------------------------------
你就是想用ID查询这个数据
然后用获取的对象 筛选掉district 和ccompanies属性
然后返回到页面请求 是吗?
我看来看去可能的错误就是在apply里面
这个System.out.println("village name:"+name); 有打出null的时候吗?
最好是在apply方法里面打个断点debug一下!
只能看出是 GetVillageAction.java的71行 某个对象执行方法时 由于这个对象是null 才报的错
要更详细的 请把代码贴出来看看
---------------------------------------
你就是想用ID查询这个数据
然后用获取的对象 筛选掉district 和ccompanies属性
然后返回到页面请求 是吗?
我看来看去可能的错误就是在apply里面
这个System.out.println("village name:"+name); 有打出null的时候吗?
最好是在apply方法里面打个断点debug一下!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请问楼主解决了吗?我这问题和你这里的很像
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询