2014-12-05 40 views
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) 
+1

哪一行是282? – agad 2014-12-05 14:46:12

+0

不要在ui线程上进行联网。但这不是问题。你有没有试图找出事实上是空的?这个消息非常明确。 – Fildor 2014-12-05 14:51:11

+0

第282行是clientOutputStream.writeObject(logonU.getMessage()); 我试图看看是否有任何变量被发送为空,但它们都打印出来的控制台罚款 – 2014-12-05 15:00:00

回答

0

是“clientOutputStream or logonU`为空。