日期:2014-05-17  浏览次数:20690 次

求教一个奇异的空指针的问题
写了一个封装关于PageBean分页的方法,返回一个String,老方法太长,怕大神看的麻烦,就随便写了点,依然报错
方法如下

public String PageFooter(String url,int pages, PageBean pb){
String strFooter = "";
strFooter = "共有"+pb.getPageTotalCount()+"页&nbsp&nbsp当前是第"+pb.getCurrentPage()+"页";
return strFooter;
}

在调用方法时用了几个syso验证了下输出
System.out.println(url); 
System.out.println(pages);
System.out.println(""+pb.getCurrentPage()+"@"+pb.getPageSize()+"@"+pb.getPageTotalCount()+"@"+pb.getTotalCount());
System.out.println( pBiz.getPageString(url, pages, pb));
前三个方法分别显示
loginLog
1
1@13@2@14
到第4个方法时就报错了,打了下断点,按F5发现这样,先进了
  public int intValue() {
return value;
  }
方法,然后进了
  public InvocationTargetException(Throwable target) {
super((Throwable)null); // Disallow initCause
  this.target = target;
  }

  public Exception(Throwable cause) {
  super(cause);
  }

  public Throwable(Throwable cause) {
  fillInStackTrace();
  detailMessage = (cause==null ? null : cause.toString());
  this.cause = cause;
  }

 最后进了几个抛出异常的方法就报错了,整了半天也不明白,望大神赐教,在线等,谢谢了!

------解决方案--------------------
不如你直接把空指针异常信息贴出来,然后顺便说下异常信息中指明的代码行号究竟是哪行代码。
------解决方案--------------------
话说你105行是哪一行啊?

只能猜测是pBiz为空了,你System.out.println输出看看吧。 

似乎你应该是用AOP来设置pBiz的,检查下为啥没有设置到值吧。
------解决方案--------------------
pBiz为null了,检查下setter方法,必要时检查下名字,可能pBiz命名有问题,生成setter方法时可能有问题的,我前段时间遇到过这种情况,不知道与你的情况是否相同,我的代码是private ILoginService fLoginService;public void setFLoginService(ILoginService fLoginService) {
this.fLoginService = fLoginService;}就出现了问题,后来把fLoginService换成了loginService就好了,仅在此分享下经历