1
發送字節我有一個JComboBox,使用這些值:從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();
}
我在做什麼錯在這裏?如果這是顯而易見的道歉,這是我的第一個項目。