为什么我得到一个Null指针异常将串行数据发送到arduino

时间:2012-09-28 01:56:29

标签: java nullpointerexception

这是堆栈的一部分:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at me.lorenjz.com.SerialComms.sendStuff(SerialComms.java:122)
at me.lorenjz.com.MainWindowC.actionPerformed(MainWindowC.java:82)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)

sendStuff:

    public synchronized void sendStuff(String messageString){
        //System.out.print("The message being sent is:  " + messageString);
        String stupid = "button";
            try {
122:                output.write(stupid.getBytes());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

    }

这是应该将字符串发送到“sendStuff”的按钮

public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

        //JOptionPane.showMessageDialog(null, "Stuff has happened");
        SerialComms SC = new SerialComms();
        SC.sendStuff("Button");
    }

我在这里做错了什么?

洛伦

添加了代码:

    public static void main(String[] args){
     System.out.println("Started onCreate");
     MainWindowC nw = new MainWindowC();
     MixWindowTwo mwt = new MixWindowTwo();
     System.out.println("Started second window");
     SerialComms SC = new SerialComms();
        SC.initialize();

}

1 个答案:

答案 0 :(得分:1)

显然,output尚未创建。