这个空指针真的很烦我——请帮忙!
任何人都可以帮我解决以下空指针异常问题:
AjaxButton viewResult = new AjaxButton("test"){
protected void onSubmit(AjaxRequestTarget target,Form form){
try {
retrieveTestID();
System.out.println(testID);
} catch (Exception e1) {
e1.printStackTrace();
}
results=new ArrayList();
DB db=new DB();
try{
db.connect();
String query =
"Select Stud_Username,result from students2tests where Test_ID="
+ testID;
System.out.println(query);
ResultSet rs=db.execSQL(query);
while(rs.next()){
Result result = new Result( rs.getString("Stud_Username"),
rs.getInt("result"));
results.add(result);
}
if(results.isEmpty()){
System.out.println("I'm empty, there is error");
}
else{
//this is being printed so results isnt empty
System.out.println("NOT EMPTY");
}
db.close();
/***seems to be throwing an error because of this line***/
ResultsTable table=new ResultsTable(results);
setResponsePage(table);
}catch(Exception e){
e.printStackTrace();
}
}
}
这是 ReesultsTable 类(数据视图)
public class ResultsTable extends BasePage {
private ArrayList resultsList;
public ResultsTable(ArrayList res){
res=resultsList;
if(resultsList.isEmpty()){
System.out.println("I am empty,beware");
}else{
System.out.println("I am not emty-no worries!!!");
}
final DataView dataView = new DataView("studresult",
new ListDataProvider(resultsList)) {
public void populateItem(final Item item) {
final Result studres = (Result) item.getModelObject();
item.add(new Label("username", studres.getUsername()));
item.add(new Label("result", "" + studres.getResult()));
}
};
dataView.setItemsPerPage(10);
add(dataView);
add(new PagingNavigator("navigator", dataView));
}
}
非常感谢
Can anyone help me with the following null pointer exception issue please:
AjaxButton viewResult = new AjaxButton("test"){
protected void onSubmit(AjaxRequestTarget target,Form form){
try {
retrieveTestID();
System.out.println(testID);
} catch (Exception e1) {
e1.printStackTrace();
}
results=new ArrayList();
DB db=new DB();
try{
db.connect();
String query =
"Select Stud_Username,result from students2tests where Test_ID="
+ testID;
System.out.println(query);
ResultSet rs=db.execSQL(query);
while(rs.next()){
Result result = new Result( rs.getString("Stud_Username"),
rs.getInt("result"));
results.add(result);
}
if(results.isEmpty()){
System.out.println("I'm empty, there is error");
}
else{
//this is being printed so results isnt empty
System.out.println("NOT EMPTY");
}
db.close();
/***seems to be throwing an error because of this line***/
ResultsTable table=new ResultsTable(results);
setResponsePage(table);
}catch(Exception e){
e.printStackTrace();
}
}
}
This is the ReesultsTable class(a dataview)
public class ResultsTable extends BasePage {
private ArrayList resultsList;
public ResultsTable(ArrayList res){
res=resultsList;
if(resultsList.isEmpty()){
System.out.println("I am empty,beware");
}else{
System.out.println("I am not emty-no worries!!!");
}
final DataView dataView = new DataView("studresult",
new ListDataProvider(resultsList)) {
public void populateItem(final Item item) {
final Result studres = (Result) item.getModelObject();
item.add(new Label("username", studres.getUsername()));
item.add(new Label("result", "" + studres.getResult()));
}
};
dataView.setItemsPerPage(10);
add(dataView);
add(new PagingNavigator("navigator", dataView));
}
}
Thank you so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ResultsTable 构造函数中,您始终将成员变量 resultsList(初始化为 null)保存到 res ArrayList 参数中。交换第一行的两边,也许就可以了。换句话说,您希望构造函数的第一行是
In your ResultsTable constructor, you are always saving the member variable resultsList (initialized to null) to the res ArrayList parameter. Swap the sides of the first line, and it might be OK. In other words, you want the first line of the constructor to be