Keep getting error and don't know how to fix...
ok, I keep getting this nullPointerException error.. and I have no clue what I've done wrong.... I believe its on the client side of it... because when I run just the client.. the try catch should make it be like "can't find host" but instead.. it just sits there.. the cursor blinking.. and Idk why.. so if you could please help me!!!!!!! heres the server and client code
import java.net.*;
import java.io.*;
publicclass SocketServerextends Thread
{
privatestatic Socket socket =null;
staticboolean forever =true;
static RTS2 rts;
publicstaticvoid main(String[] args)throws Exception
{
ServerSocket serverSocket =null;
try{
serverSocket =new ServerSocket(5454);
}catch (IOException e){
System.err.println("Could not listen on port.");
System.exit(1);
}
Socket clientSocket =null;
try{
clientSocket = serverSocket.accept();
}catch (IOException e){
System.err.println("Accept failed.");
System.exit(1);
}
while(forever)
{
try{
ObjectOutputStream oos =
new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(rts.getCompany());
ObjectInputStream ois =
new ObjectInputStream(socket.getInputStream());
rts.setEnemy((Men)ois.readObject());
socket.close();
}catch (Exception e){
System.out.println(e);
e.printStackTrace();
}
}
}
}
import java.net.*;
import java.io.*;
publicclass SocketClient
{
staticboolean forever=true;
static RTS2 rts;
static Socket socket =null;
static ObjectInputStream ois =null;
static ObjectOutputStream oos =null;
publicstaticvoid main(String[] args)throws Exception
{
try{
socket =new Socket("josh", 5455);
ois =new ObjectInputStream(socket.getInputStream());
oos =new ObjectOutputStream(socket.getOutputStream());
}catch (UnknownHostException e){
System.err.println("Don't know about host");
System.exit(1);
}catch (IOException e){
System.err.println("Couldn't get I/O for the connection");
System.exit(1);
}
while(forever)
{
rts.setEnemy((Men)ois.readObject());
System.out.println("hello");
oos.writeObject(rts.getCompany());
oos.flush();
}
}
}

