java.lang.NullPointerException

armi100 2010-06-03 06:28:48
Struts Problem Report
Struts has detected an unhandled exception:

Messages:
File: com/sterning/books/web/actions/BooksAction.java
Line number: 40


--------------------------------------------------------------------------------

Stacktraces
java.lang.NullPointerException
com.sterning.books.web.actions.BooksAction.list(BooksAction.java:40)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)




package com.sterning.books.web.actions;

import java.util.Collection;

import com.sterning.books.model.Books;
import com.sterning.books.services.iface.IBooksService;
import com.sterning.commons.AbstractAction;
import com.sterning.commons.Pager;
import com.sterning.commons.PagerService;

public class BooksAction extends AbstractAction {

private IBooksService booksService;
private PagerService pagerService;

private Books book;
private Pager pager;

protected Collection availableItems;
protected String currentPage;
protected String pagerMethod;
protected String totalRows;
protected String bookId;
protected String queryName="1";
protected String queryValue="1";
protected String searchName;
protected String searchValue;
protected String queryMap;

public String list() throws Exception {
if(queryMap ==null||queryMap.equals("")){

}else{
String[] str=queryMap.split("~");
this.setQueryName(str[0]);
this.setQueryValue(str[1]);
}

//System.out.println("asd1"+this.getQueryValue());
//这里出错,网上的例子来的。。。。。: http://blog.csdn.net/zhicc/archive/2009/07/28/4386849.aspx
int totalRow=booksService.getRows(this.getQueryName(),this.getQueryValue());
pager=pagerService.getPager(this.getCurrentPage(), this.getPagerMethod(), totalRow);

this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
this.setTotalRows(String.valueOf(totalRow));
availableItems=booksService.getBooks(this.getQueryName(),this.getQueryValue(),pager.getPageSize(), pager.getStartRow());

this.setQueryName(this.getQueryName());
this.setQueryValue(this.getQueryValue());

this.setSearchName(this.getQueryName());
this.setSearchValue(this.getQueryValue());

return SUCCESS;
}
...全文
145 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
armi100 2010-06-04
  • 打赏
  • 举报
回复
顶上去
armi100 2010-06-04
  • 打赏
  • 举报
回复
单点调试到这行出错:
40: int totalRow=booksService.getRows(this.getQueryName(),this.getQueryValue());
debug 以后都是系统的代码了,应该到这里就出错了。
tcmis 2010-06-04
  • 打赏
  • 举报
回复
Line number: 40
哪行能不能标注一下呢,,还让大家一行一行的数????
armi100 2010-06-04
  • 打赏
  • 举报
回复
解决了,private IBooksService booksService;先初始化 改成:
private IBooksService booksService=new BooksService();
armi100 2010-06-03
  • 打赏
  • 举报
回复
顶上去
armi100 2010-06-03
  • 打赏
  • 举报
回复
单点调试到这行出错:
int totalRow=booksService.getRows(this.getQueryName(),this.getQueryValue());
debug 以后都是系统的代码了,应该到这里就出错了。
ladybirds2008 2010-06-03
  • 打赏
  • 举报
回复
debug 调试啊 一下就能定位问题点啦。。。看代码哪能这么好的眼力啊。。。嘿。。。
armi100 2010-06-03
  • 打赏
  • 举报
回复
单点调试到这行出错:
int totalRow=booksService.getRows(this.getQueryName(),this.getQueryValue());

然后自己给this.getQueryName()和this.getQueryValue()); 赋值也不行
armi100 2010-06-03
  • 打赏
  • 举报
回复
例子照网上copy:http://blog.csdn.net/zhicc/archive/2009/07/28/4386849.aspx
lintemp1 2010-06-03
  • 打赏
  • 举报
回复
额,你给的代码不够全,我没发现你的getQueryValue()方法在哪里
gulang76 2010-06-03
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 gulang76 的回复:]

Java code

package com.sterning.books.web.actions;

import java.util.Collection;

import com.sterning.books.model.Books;
import com.sterning.books.services.iface.IBooksService;
import com.sterning.c……
[/Quote]

看注释
gulang76 2010-06-03
  • 打赏
  • 举报
回复

package com.sterning.books.web.actions;

import java.util.Collection;

import com.sterning.books.model.Books;
import com.sterning.books.services.iface.IBooksService;
import com.sterning.commons.AbstractAction;
import com.sterning.commons.Pager;
import com.sterning.commons.PagerService;

public class BooksAction extends AbstractAction {

private IBooksService booksService;
private PagerService pagerService;

private Books book;
private Pager pager;

protected Collection availableItems;
protected String currentPage;
protected String pagerMethod;
protected String totalRows;
protected String bookId;
protected String queryName="1";
protected String queryValue="1";
protected String searchName;
protected String searchValue;
protected String queryMap;

public String list() throws Exception {
//if(queryMap ==null||queryMap.equals("")){
//如果queryMap 为空时,queryMap.equals("")这句会报空指针错,一般改为("").equals(queryMap)
//就不会报这个错了。
//或者改为:
if(queryMap ==null){

}else if(queryMap.equals("")){

}else{
String[] str=queryMap.split("~");
this.setQueryName(str[0]);
this.setQueryValue(str[1]);
}

//System.out.println("asd1"+this.getQueryValue());
//这里出错,网上的例子来的。。。。。: http://blog.csdn.net/zhicc/archive/2009/07/28/4386849.aspx
int totalRow=booksService.getRows(this.getQueryName(),this.getQueryValue());
pager=pagerService.getPager(this.getCurrentPage(), this.getPagerMethod(), totalRow);

this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
this.setTotalRows(String.valueOf(totalRow));
availableItems=booksService.getBooks(this.getQueryName(),this.getQueryValue(),pager.getPageSize(), pager.getStartRow());

this.setQueryName(this.getQueryName());
this.setQueryValue(this.getQueryValue());

this.setSearchName(this.getQueryName());
this.setSearchValue(this.getQueryValue());

return SUCCESS;
}


armi100 2010-06-03
  • 打赏
  • 举报
回复
int totalRow=booksService.getRows(this.getQueryName(),this.getQueryValue());
给this.getQueryName()和this.getQueryValue()); 赋值也不行,我用的是myeli..8.0
armi100 2010-06-03
  • 打赏
  • 举报
回复
顶上去
armi100 2010-06-03
  • 打赏
  • 举报
回复
请高手赐教,谢谢

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧