1
我正在接受串行输入和上载COSM服务器上接收到的数据的Java程序。存储从串口收到数据的全局变量不会在用于更新COSM的方法中重现该值。请有人告诉我这有什么问题吗? 我甚至使用的全局队列对象之前,但删除时被调用Update方法NullPointerException
队列对象上抛出。值不转载其他方法
public synchronized void serialEvent(SerialPortEvent oEvent)//Event handler for serial communication
{
if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE)
{
try {
val = input.read();
this.update(78164);
} catch (PachubeException e) {
// If an exception occurs it will print the error message from the
// failed HTTP command
System.err.println(e.errorMessage);
//System.out.println("Main method");
} catch (IOException e) {
System.err.println(e);
// System.out.println("Main method");
} catch (Exception e) {
// System.out.println("Main method");
System.err.println(e);
}
}
val
是全局变量。当在update
方法的val
值是零或20称为(与val
值在其定义中被初始化)。 这里的更新方法的实现:
private void update(int feedid) throws PachubeException, IOException ,Exception
{
Feed f = this.pachube.getFeed(feedid);
System.out.println("updating ...");
f.updateDatastream(8345, (double) val);
f.updateDatastream(6274, (double) val);
f.updateDatastream(1044, (double) val);
// f.updateDatainputDatastream((f.getData(), in, out, true));
//System.out.println(val);
System.out.println("updated");
}
告诉我们如何更新()的实施,以及在何处以及如何VAL声明。 – 2013-03-23 18:04:42
'NullPointerException'正在抛出,因为'f'可能没有被初始化。检查'pachube.getFeed(feedid)'是否返回对'Feed'类的实例的引用。 – 2013-03-23 18:14:16
我不认为这是一个问题,因为当数据被分配到队列对象的更新方法本身值显示在输出控制台 – 2013-03-23 18:30:29