【发布时间】:2016-07-05 08:17:06
【问题描述】:
我有一个带有这些值的 jComboBox:
String[] preset = { "1", "2", "3", "4", "5" };
因此,如果选择“1”,那么我想向我的 OutputStream 添加一个字节。
byte preset1 = 0X01;
基于组合框中的选择。我认为可能是这样,但它给出了 NullPointerException。
byte preset = (byte)setPresetcomboBox.getSelectedItem();
try {
byte[] command = {(byte) startTx, address, setPreset, 0x00, preset, endTx, 0x0F};
TwoWaySerialComm.SerialWriter sw = new TwoWaySerialComm.SerialWriter(
twoWaySerCom.serialPort.getOutputStream());
sw.out.write(command);
} catch (IOException e) {
e.printStackTrace();
}
我在这里做错了什么?抱歉,如果这很明显,这是我的第一个项目。
【问题讨论】: