0
我試圖通過用ObjectOutputStream發送一個字符串,我不斷收到一個空指針異常錯誤多數民衆贊成失敗的代碼是在這裏發送字符串通過ObjectOutputStream的JAVA網絡
try
{ // get username from text field and encrypt
String uname = username.getText();
EncryptMess logonU = new EncryptMess(uname); //Sends to be encrypted
logonU.encrypt(); //Ecryption is ran
String sendUname = logonU.getMessage(); // String is returned
// get password from password field and encrypt
String pword = password.getText();
EncryptedMessage logonP = new EncryptedMessage(pword);
logonP.encrypt();
String sendPword = logonP.getMessage();
// This prints out the encrypted messages perfectly, put in to troubleshoot
System.out.println("1) " + sendUname + "\n2)" + sendPword + "\n");
// send encrypted username to server
clientOutputStream.writeObject(logonU.getMessage());
// send encrypted password to server
clientOutputStream.writeObject(logonP.getMessage());
}
然後我得到這個錯誤的行它被寫對象到插座首先,我得到這個即將到來的控制檯錯誤
Exception in thread "AWT-EventQueue-0"
java.lang.NullPointerException
at Chat_Client.sendLoginDetails(Chat_Client.java:282)
哪一行是282? – agad 2014-12-05 14:46:12
不要在ui線程上進行聯網。但這不是問題。你有沒有試圖找出事實上是空的?這個消息非常明確。 – Fildor 2014-12-05 14:51:11
第282行是clientOutputStream.writeObject(logonU.getMessage()); 我試圖看看是否有任何變量被髮送爲空,但它們都打印出來的控制檯罰款 – 2014-12-05 15:00:00