我试图通过objectOutputStream发送一个字符串,并且我一直得到一个空指针异常错误代码失败的代码在这里
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)
答案 0 :(得分:0)
'clientOutputStream or
logonU`为空。