Answer the question
In order to leave comments, you need to log in
Exception in thread "main" java.lang.NullPointerException how to fix?
package Default;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Connect {
int port = 2020;
ServerSocket s;
Scanner in ;
PrintWriter w;
private void connect() {
Socket socket;
try {
socket = s.accept();
} catch(IOException e) {
JOptionPane.showMessageDialog(null, "Не могу установить соединение");
return;
}
JOptionPane.showMessageDialog(null, "Соединение установлено");
try { in =new Scanner(socket.getInputStream());
w = new PrintWriter(socket.getOutputStream(), true);
} catch(IOException e) {
return;
}
JOptionPane.showMessageDialog(null, in);
}
public void sendClient(String command) {
}
public void Server() {
try {
s = new ServerSocket(port);
} catch(IOException e) {
JOptionPane.showMessageDialog(null, "Не могу создать сервер");
System.exit(0);
}
}
public void processing() {
while (true) {
connect();
}
}
}
Exception in thread "main" java.lang.NullPointerException
at Default.Connect.connect(Connect.java:21)
at Default.Connect.processing(Connect.java:54)
at Default.Server.main(Server.java:8)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question