从该线程中的另一个线程和类访问静态向量时遇到问题。一个类是名为 LotteryPlay 的 GUI 类,它有一个名为 packArray 的静态 Vector,另一个类是 MultiThreader,它的一部分如下所示,它在不同的线程中运行。关于什么是错的任何想法?
我唯一能想到的是我正在尝试从另一个线程访问静态向量。这可能吗?
@Override
public void run() {
try {
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("streams are setup from new thread\n");
line = "";
while((line = in.readLine())!= null){
this.messageFromClient(line);
if(!(counter > 1)){
textSplitter(line);
socketPack = new SocketPack(socket, timeStamp, address);
LotteryPlay.packArray.add(socketPack); <<<----NULL POINTER EXCEPTION
System.out.println("SIZE OF PACKARRAY " + LotteryPlay.packArray.size());
System.out.println();
System.out.println("pakc array "+ LotteryPlay.packArray);
}
System.out.println("from client: " + line.trim() + "\n");
} // end while loop
java.lang.Thread.run(Thread.java:662) 处的线程“Thread-3”java.lang.NullPointerException at.com.lotterygame.MultiThreader.run(MultiThreader.java:55) 中的异常