沒錯誤但跑的時候出錯~可以幫我看看哪裡出問題了嗎?
serverIp = InetAddress.getByName("XXX.XXX.XX.XX");
socket =new Socket(XXX,XXX);
socket.setSoTimeout(1000);
DataOutputStream bw = new DataOutputStream(socket.getOutputStream());
char[] result2={0x00,0x00,0x00,0x11};
for(int i=0;i<result2.length;i++)
{
byte[] d = null;
d[i]=(byte)result2[i];
bw.write(d);
}
------解决方案--------------------
byte[] d = null;
d等于null,你怎么给d[i]赋值?
正确的写法是
serverIp = InetAddress.getByName("XXX.XXX.XX.XX");
socket =new Socket(XXX,XXX);
socket.setSoTimeout(1000);
DataOutputStream bw = new DataOutputStream(socket.getOutputStream());
char[] result2={0x00,0x00,0x00,0x11};
byte[] d = new byte[result2.length];
for(int i=0;i<result2.length;i++)
{
d[i]=(byte)result2[i];
}
bw.write(d);