日期:2014-05-20  浏览次数:20715 次

高手快来,奇怪的问题!!在线等待!!!(高分求救)
try{
  ByteArrayInputStream bais=new ByteArrayInputStream(bytedata);  
  DataInputStream dis=new DataInputStream(bais);
  a=dis.readInt();
  data=dis.readUTF();
  bais.close();
  dis.close();
  }catch (IOException ioe){
  System.out.println("发生错误!");
  ioe.printStackTrace();
  }

出现空指针这段代码,下面是错误信息
java.lang.NullPointerException
at javax.microedition.lcdui.Form.append(+11)
at FindBusStop.BusStopsFind(+118)
at FindBusStop.commandAction(+63)
at javax.microedition.lcdui.List.callKeyPressed(+80)
at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(+198)
at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(+11)
at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(+121)
at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(+210)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+178)
java.lang.NullPointerException
把后面的注释掉,就剩下ByteArrayInputStream bais=new ByteArrayInputStream(bytedata); 就会出现那个错误的,我是要操作数据库的,所以这里必须需要字节转化,谁帮我看看到底是怎么回事?我查找书上的代码都这样的呀,很奇怪。

------解决方案--------------------
看错误应该是你在向Form中添加项的时候报的错
------解决方案--------------------
似乎是你的form 要append的对象是null,请仔细查看一下。
可能是由于你的数据没有读完,而无法创建append的对象吧。
这段代码实在看不出为什么会跑Null异常

saltedfish