henven130 2004年12月27日
JAVA基础问题
下面是一条程序的片断
public class CommConnection implements SerialPortEventListener
{
....
public void CommWrite(String messageString)
{
try {
outputStream.write(messageString.getBytes());
//表示CTRL+Z
//outputStream.write((char)26);
} catch (IOException e) {}
readwait(500);
}
.....
public String readmsg(int msgType)
{
String fanxitemp="";
openConnect();
String isOK;
CommWrite("AT+CMGF=0\r");
isOK=CommReadWait(message);
readwait(500);
msgcount=0;
message="";
CommWrite("AT+CMGL="+msgType+"\r");
try
{
do
{
readwait(500);
}while (!message.substring(message.length()-4,message.length()-2).trim().equals("OK"));
//System.out.println(message.length());
StringTokenizer tt=new StringTokenizer(message.substring(12,message.length()-2),"+");
int ttcount=tt.countTokens();

while (tt.hasMoreElements())
{
String tempstr=tt.nextToken();
//System.out.println(tempstr);
//System.out.println(tempstr.substring(15,tempstr.length()).trim().length());
try{
if (fanxitemp.equals(""))
{
fanxitemp=fanxi(tempstr.substring(15,tempstr.length()).trim());
}
else
{
fanxitemp=fanxitemp+"◎"+fanxi(tempstr.substring(15,tempstr.length()).trim());
}
//System.out.println(fanxitemp);
}
catch(Exception eeee)
{System.out.println(eeee.getMessage());}
}
//System.out.println(fanxitemp);
//System.out.println(msgcount);
}
catch(Exception ess)
{}
closeConnect();
message="";
return fanxitemp;
}

public static void main(String[] args)
{
new CommConnection();
//System.out.println("AT+CMGL=\"ALL\"");
//System.exit(0);
}
.....
}
java.lang.NullPointerException
sms.CommConnection.CommWrite(CommConnection.java:109)
sms.CommConnection.readmsg(CommConnection.java:266)
org.apache.jsp.msgbox_jsp._jspService(msgbox_jsp.java:72)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


如果有public static void main(String[] args)就可以正常运行,但我将它改成been时在
其它页面调用readmsg()就会出现下列错误
...全文
69 点赞 收藏 2
写回复
2 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Java SE
创建于2007-09-28

3.4w+

社区成员

30.7w+

社区内容

Java 2 Standard Edition
社区公告
暂无公告