日期:2014-05-20 浏览次数:20830 次
public class SocketConn { public StreamConnection conn; public DataOutputStream outputStream; public DataInputStream inputStream; public SocketConn() { try { if (null == conn) { conn = (StreamConnection) Connector.open("socket://222.90.231.60:22616", Connector.READ_WRITE); } } catch (Exception e) { e.printStackTrace(); } } } public class RequestDataImpl extends SocketConn implements IRequestData{ //requestKeys()这个方法是没问题的,能正常发送、接收数据 public void requestKeys() { try { outputStream = conn.openDataOutputStream(); outputStream.write(getConvert().hexStringToBytes(REQKEYSTR)); outputStream.flush(); inputStream = conn.openDataInputStream(); // ... } catch (IOException e) { } } public void loginSer() { try { [color=#FF0000] //[b]问题:[/b]在conn.openDataOutputStream()的时候抛空指针(nullProintException)异常[/color] outputStream = conn.openDataOutputStream(); outputStream.write("login"); outputStream.flush(); inputStream = conn.openDataInputStream(); //... } catch (IOException e) { } } }
IRequestData reqData = new RequestDtaImpl(); reqData.requestKey(); reqData.loginSer();