下面这个action,为什么JSONArray jsonlist = JSONArray.fromObject( "['json','is','easy']" );会异常呢
<2012-11-8下午11时15分02秒GMT+08:00><Error><HTTP><BEA-101020><[ServletContext@5667705[app:...
<2012-11-8 下午11时15分02秒 GMT+08:00> <Error> <HTTP> <BEA-101020> <[ServletContext@5667705[app:_appsdir_testWebForEJB_dir module:testWebForEJB path:/testWebForEJB spec-version:2.5]] Servlet failed with Exception
java.lang.NullPointerException
at weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:622)
at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:666)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:771)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
Truncated. see log file for complete stacktrace
>
代码如下:
package com.jackie.action;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.jackie.entity.PMaxIdEntity;
import com.jackie.entity.userEntity;
import com.jackie.service.MaxIdService;
public class PMaxId {
MaxIdService service;
List<PMaxIdEntity> maxidList;
public String getMaxId(){
//maxidList = service.queryAll();
List<userEntity> userlist = new ArrayList<userEntity>();
userEntity user1 = new userEntity();
user1.setPassword("123123");
user1.setUsername("user1");
userEntity user2 = new userEntity();
user2.setPassword("345345");
user2.setUsername("user2");
userlist.add(user1);
userlist.add(user2);
JSONArray jsonlist = JSONArray.fromObject( "['json','is','easy']" );
System.out.println(jsonlist);
JSONObject jsondata = JSONObject.fromObject(user1);
System.out.println(jsondata);
return null;
}
public MaxIdService getService() {
return service;
}
public void setService(MaxIdService service) {
this.service = service;
}
public List<PMaxIdEntity> getMaxidList() {
return maxidList;
}
public void setMaxidList(List<PMaxIdEntity> maxidList) {
this.maxidList = maxidList;
}
} 展开
java.lang.NullPointerException
at weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:622)
at weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:666)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:771)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
Truncated. see log file for complete stacktrace
>
代码如下:
package com.jackie.action;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.jackie.entity.PMaxIdEntity;
import com.jackie.entity.userEntity;
import com.jackie.service.MaxIdService;
public class PMaxId {
MaxIdService service;
List<PMaxIdEntity> maxidList;
public String getMaxId(){
//maxidList = service.queryAll();
List<userEntity> userlist = new ArrayList<userEntity>();
userEntity user1 = new userEntity();
user1.setPassword("123123");
user1.setUsername("user1");
userEntity user2 = new userEntity();
user2.setPassword("345345");
user2.setUsername("user2");
userlist.add(user1);
userlist.add(user2);
JSONArray jsonlist = JSONArray.fromObject( "['json','is','easy']" );
System.out.println(jsonlist);
JSONObject jsondata = JSONObject.fromObject(user1);
System.out.println(jsondata);
return null;
}
public MaxIdService getService() {
return service;
}
public void setService(MaxIdService service) {
this.service = service;
}
public List<PMaxIdEntity> getMaxidList() {
return maxidList;
}
public void setMaxidList(List<PMaxIdEntity> maxidList) {
this.maxidList = maxidList;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询