为什么我的printwriter会抛出nullpointer错误

为什么我的printwriter会抛出nullpointer错误

本文介绍了为什么我的printwriter会抛出nullpointer错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好几天我都遇到这种情况我无法解决我试图用户使用print write将用户输入的文本或数字发送到Server类但是每次我点击提交后都出现错误按钮。 我是java新手请帮助我。 这是Client.Java import javafx.application.Application; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.scene.control。*; import java.io.IOException; import java.net。*; import java.io.PrintWriter; import java.util.Scanner; public class 客户扩展应用程序 // 用于GUI { private PrintWriter outputToServer; // 向服务器发送消息 private 扫描仪inputFromServer; // 从服务器获取响应 // 私有字符串用户名; 私有套接字套接字; private static InetAddress host = null; final int PORT = 1234 ; public static void main( String [] args){ try { host = InetAddress.getLocalHost(); } catch (UnknownHostException ex){ System.out.println( 找不到主机ID); } 做 { launch(args); } while (true); } public void start(阶段阶段) throws 例外{ // 设置变量 socket = new Socket(host,PORT); // 扫描程序设置,以便它可以扫描来自服务器的任何输入流(响应) inputFromServer = new Scanner(socket.getInputStream()); outputToServer = new PrintWriter(socket.getOutputStream(),true); 父root = FXMLLoader.load(getClass()。getResource( welcome.fxml)); 场景场景; scene = new 场景(root, 500 , 500 ); // 将场景添加到舞台 stage = new Stage(); stage.setScene(场景); stage.show(); } @ FXML private TextField输入; @ FXML private void loginButton(ActionEvent event) { String t = Input.getText(); // validateUsername(t); System.out.println(t ); validateUsername(t); } @ FXML private void validateUsername( String username){ if (username.isEmpty()){ // message.setText(Please输入您的用户名); } else { // 将用户名发送到服务器 System.out.println(username); outputToServer.println(username); 字符串 serverRequest = inputFromServer.nextLine(); if (serverRequest.equals( true)){ LoadClient(); } } } private void LoadClient() {场景场景; VBox vbox; 舞台舞台; 按钮收件箱= 新按钮( 收件箱); 按钮电子邮件= 新按钮( 电子邮件); Button quit = new 按钮( 退出); inbox.setOnAction(e - > getInbox()); email.setOnAction(e - > getEmail()); quit.setOnAction(e - > quitApp()); // 添加布局按钮 vbox = new VBox(); vbox.getChildren()。add(inbox); vbox.getChildren()。add(email); vbox.getChildren()。add(quit); scene = 新场景(vbox, 500 , 500 ); stage = new Stage(); stage.setScene(场景); stage.show(); } public void getInbox(){ System.out.println( SENDING INBOX REQUEST); outputToServer.println( get_inbox); System.out.println( SENDING INBOX REQUEST); } public void getEmail(){ outputToServer.println( send_email); } public void quitApp(){ outputToServer.println( close); } 这是Server.java import javafx.fxml.FXML; import java.io.IOException; import java.io.Serializable; import java.lang.reflect.Array; import java.net.ServerSocket; import java.util.ArrayList; import java.net。*; import java.io. *; import java.util.Scanner; public class 服务器 implements Serializable // 用于将对象从客户端发送到服务器 { // 字符串类型的用户列表 private static ArrayList< String> users = new ArrayList< String>(); private static ArrayList< Email> mails = new ArrayList< Email>(); public static void main( String [] args) throws IOException { // 设置3个用户 users.add( U1); users.add( U2); users.add( U3); 套接字客户端; // client ServerSocket serverSocket = null; // server final int PORT = 1234 ; ClientHandler clientHandler; // 设置服务器套接字 尝试 { serverSocket = new ServerSocket( 1234 ); } catch (IOException ioEx) { System.out.println( 无法设置端口); System.exit( 1 ); } System.out.println( \ n服务器正在运行 ); do { client = serverSocket.accept(); // 接受客户端到服务器 // 创建一个验证用户的函数 String validUser = validateUser (客户); clientHandler = new ClientHandler(validUser,client); clientHandler.start(); // 调用运行函数 } while (true); } private static 字符串 validateUser(套接字客户端) {扫描器inputFromClient = null; PrintWriter outputToClient = null; boolean validUser = false; 尝试 { // 允许服务器从客户端检索输入 inputFromClient = new Scanner(client.getInputStream() ); // 允许服务器向客户端发送内容 outputToClient = new PrintWriter(client.getOutputStream(),true); } catch (IOException io) { System.out.println( 初始化变量的问题); } // 从客户端获取输入 String userToValidate = inputFromClient.nextLine(); while (validUser == false) { for (字符串用户名:users) { // 检查用户验证是否与客户端的用户匹配 if (username.equals(userToValidate)) { // 告诉客户端用户有效 validUser = true; break ; } } if (validUser == false) { // 用户无效,等待新用户从客户端传递到服务器 outputToClient .println( false); userToValidate = inputFromClient.nextLine(); } else { outputToClient.println( true); } } // 返回正确的用户名 return userToValidate; } // 获取邮件来自服务器,因此可以在clienthandler中访问它 private static ArrayList< ;电子邮件与GT; getMail() { return 邮件; } } // 每个客户都有其独特之处用户名 类 ClientHandler extends 线程 implements Serializable { private Socket客户端; // 从客户端检索请求 私人扫描仪输入; // 向客户发送请求 私人 PrintWriter输出; private String username; public ClientHandler( String 用户名,套接字客户端) { 此 .username = username; 此 .client = client; System.out.println( BEFORE TRY); 尝试 { input = 新扫描程序(client.getInputStream) ()); output = new PrintWriter(client.getOutputStream(),true); } catch (IOException io) { System.out.println( 客户端处理程序未正确设置); } } public void run() { // 从服务器接收请求 String request = input.nextLine(); System.out.println(request); // 检查请求 while (!request.equals( close)) { // 做任何用户想做的事 if (request.equals( get_inbox)) { System.out.println( INSIDE INBOX REQUEST); } else if (request.equals( send_email)) { System.out.println( INSIDE SEND EMAIL REQUEST); } request = input.nextLine(); // 从服务器获取新请求 } // 结束客户端连接 尝试 { System.out.println( 结束连接); client.close(); } catch (IOException io) { System.out.println( Coulnd close close); } } 这是我的错误日志 在javafx.fxml.FXMLLoader $ ControllerMethodEventHandler.handle(FXMLLoader.java: 1657 ) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java: 86 ) at com.sun.javafx.event.EventHandlerManager。 dispatchBubblingEvent(EventHandlerManager.java: 238 ) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java: 191 ) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java: 59 ) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 58 ) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent( EventDispatchChainImpl.java: 114 ) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 56 )com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java: 114 ) com.sun.javafx上的。 event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 56 ) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java: 114 ) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java: 74 ) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java: 49 ) at javafx.event.Event.fireEvent( Event.java: 198 ) at javafx.scene.Node.fireEvent(Node.java: 8413 ) at javafx.scene.control.Button.fire(Button.java: 185 ) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java: 182 ) at com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java: 96 ) at com.sun.javafx .scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java: 89 ) at com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent (CompositeEventHandler.java: 218 ) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java: 80 ) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java: 238 ) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java: 191 ) at com.sun.javafx.event.CompositeEve ntDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java: 59 ) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 58 ) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java: 114 ) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 56 ) at com.sun.javafx.event.EventDispatchChainImpl。 dispatchEvent(EventDispatchChainImpl.java: 114 ) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 56 ) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java: 114 ) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java: 74 )com.sun.javafx的。 event.EventUtil.fireEvent(EventUtil.java: 54 ) at javafx.event.Event.fireEvent(Event.java: 198 ) at javafx.scene.Scene $ MouseHandler.process(Scene.java: 3757 ) at javafx .scene.Scene $ MouseHandler.access $ 1500(Scene.java: 3485 ) at javafx.scene.Scene.impl_processMouseEvent(Scene.java: 1762 ) at javafx.scene.Scene $ ScenePeerListener.mouseEvent(Scene.java: 2494 ) at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java: 381 ) at com.sun.javafx。 tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java: 295 ) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleM ouseEvent $ 354(GlassViewEventHandler.java: 417 ) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolki t.java: 389 ) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewE ventHandler.java: 416 ) at com.sun.glass.ui.View.handleMouseEvent(View.java: 555 ) at com.sun.glass .ui.View.notifyMouse(View.java: 937 )引起:java.lang.reflect.InvocationTargetException at sun.reflect。 NativeMethodAccessorImpl.invoke0(本机方法) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: 62 ) at sun.reflect.DelegatingMethodAccessorImpl .invoke(DelegatingMethodAccessorImp l.java: 43 ) at java.lang.reflect.Method.invoke(Method.java: 498 ) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java: 71 ) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 43 ) at java.lang.reflect.Method.invoke(Method.java: 498 ) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java: 275 ) at javafx.fxml.FXMLLoader $ MethodHandler.invoke(FXMLLoader.java: 1769 ) ... 45 更多引起:java.lang.NullPointerException at Client.validateUsername(Client.java: 112 ) at Client.loginButton(Client.java: 99 ) ... 55 mor 我尝试过: 我试图找到问题,但遗憾的是任何c ode我尝试失败了。解决方案 ControllerMethodEventHandler.handle(FXMLLoader.java: 1657 ) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java: 86 ) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent( EventHandlerManager.java: 238 ) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java: 191 ) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java: 59 ) at com .sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 58 ) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl。 java: 114 )com.sun.javafx.event.BasicEven上的 tDispatcher.dispatchEvent(BasicEventDispatcher.java: 56 ) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java: 114 ) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java: 56 ) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java: 114 ) at com.sun.javafx.event.EventUtil。 fireEventImpl(EventUtil.java: 74 ) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java: 49 ) at javafx.event.Event.fireEvent(Event.java: 198 ) at javafx.scene .Node.fireEvent(Node.java: 8413 ) at javafx.scene.control.Button.fire(Button.java: 185 ) at com.sun.javafx.scene.control.behavior.ButtonBehavior。 mouseReleased(ButtonBehavior.java: 182 ) at com.sun.javafx.scene.control.skin.BehaviorSkinBase 1.handle(BehaviorSkinBase.java: 96 ) at com.sun.javafx.scene.control.skin.BehaviorSkinBase 1.handle(BehaviorSkinBase.java: 89 ) at com.sun.javafx.event.CompositeEventHandler Hi everyone it's been days that I'm stuck with this situation and I cannot resolve I'm trying to send the user entered text or numbers to the Server class using print write but every time I getting errors after I hit the submit button.Im new to java please help me.This is the Client.Javaimport javafx.application.Application;import javafx.event.ActionEvent;import javafx.fxml.FXML;import javafx.fxml.FXMLLoader;import javafx.scene.Parent;import javafx.scene.Scene;import javafx.scene.layout.VBox;import javafx.scene.text.Text;import javafx.stage.Stage;import javafx.scene.control.*;import java.io.IOException;import java.net.*;import java.io.PrintWriter;import java.util.Scanner;public class Client extends Application // for GUI{private PrintWriter outputToServer; // send message to serverprivate Scanner inputFromServer; // gets response back from the server//private String username;private Socket socket;private static InetAddress host = null;final int PORT = 1234;public static void main(String[] args) { try { host = InetAddress.getLocalHost(); } catch (UnknownHostException ex) { System.out.println("Host ID Not Found"); } do { launch(args); } while (true);}public void start(Stage stage) throws Exception { // set up variables socket = new Socket(host, PORT); // scanner set up so that it can scan for any input stream (responses) that come from the server inputFromServer = new Scanner(socket.getInputStream()); outputToServer = new PrintWriter(socket.getOutputStream(), true); Parent root = FXMLLoader.load(getClass().getResource("welcome.fxml")); Scene scene; scene = new Scene(root, 500, 500); //add the scene to the stage stage = new Stage(); stage.setScene(scene); stage.show();}@FXMLprivate TextField Input;@FXMLprivate void loginButton (ActionEvent event){ String t = Input.getText(); //validateUsername(t); System.out.println(t); validateUsername(t);}@FXMLprivate void validateUsername(String username) { if (username.isEmpty()) { // message.setText("Please enter your username"); } else { // send username across to the server System.out.println(username); outputToServer.println(username); String serverRequest = inputFromServer.nextLine(); if (serverRequest.equals("true")) { LoadClient(); } }}private void LoadClient(){ Scene scene; VBox vbox; Stage stage; Button inbox = new Button("Inbox"); Button email = new Button("Email"); Button quit = new Button("Quit"); inbox.setOnAction(e -> getInbox()); email.setOnAction(e -> getEmail()); quit.setOnAction(e -> quitApp()); // add buttons to layout vbox = new VBox(); vbox.getChildren().add(inbox); vbox.getChildren().add(email); vbox.getChildren().add(quit); scene = new Scene(vbox, 500, 500); stage = new Stage(); stage.setScene(scene); stage.show();}public void getInbox() { System.out.println("BEFORE SENDING INBOX REQUEST"); outputToServer.println("get_inbox"); System.out.println("AFTER SENDING INBOX REQUEST");}public void getEmail() { outputToServer.println("send_email");}public void quitApp() { outputToServer.println("close");}This is Server.javaimport javafx.fxml.FXML;import java.io.IOException;import java.io.Serializable;import java.lang.reflect.Array;import java.net.ServerSocket;import java.util.ArrayList;import java.net.*;import java.io.*;import java.util.Scanner;public class Server implements Serializable // used to send object from client to server{// list of users of type stringprivate static ArrayList<String> users = new ArrayList<String>();private static ArrayList<Email> mails = new ArrayList<Email>();public static void main(String[] args) throws IOException{ // set up 3 users users.add("U1"); users.add("U2"); users.add("U3"); Socket client; // client ServerSocket serverSocket = null; // server final int PORT = 1234; ClientHandler clientHandler; // set up the server socket try { serverSocket = new ServerSocket(1234); } catch (IOException ioEx) { System.out.println("Can't set up port"); System.exit(1); } System.out.println("\n Server running"); do { client = serverSocket.accept(); // accept the client to the server // create a function that will validate the user String validUser = validateUser(client); clientHandler = new ClientHandler(validUser, client); clientHandler.start(); // calls the run function } while (true);}private static String validateUser(Socket client){ Scanner inputFromClient = null; PrintWriter outputToClient = null; boolean validUser = false; try { // allows the server to retrieve the input from the client inputFromClient = new Scanner(client.getInputStream()); // allow server to send things to the client outputToClient = new PrintWriter(client.getOutputStream(), true); } catch(IOException io) { System.out.println("Problem initialising variables"); } // get the input from the client String userToValidate = inputFromClient.nextLine(); while (validUser == false) { for(String username : users) { // check the user to validate matches the user from the client if (username.equals(userToValidate)) { // tell the client that user is valid validUser = true; break; } } if(validUser == false) { // user is invalid so wait for a new user to pass from the client to the server outputToClient.println("false"); userToValidate = inputFromClient.nextLine(); } else { outputToClient.println("true"); } } // return the correct username return userToValidate;}// get the mail from the server so it can be accessed in the clienthandlerprivate static ArrayList<Email> getMail(){ return mails;}}// each client will have their unique usernameclass ClientHandler extends Thread implements Serializable{private Socket client;// retrieve requests from the clientprivate Scanner input;// send requests to the clientprivate PrintWriter output;private String username;public ClientHandler(String username, Socket client){ this.username = username; this.client = client; System.out.println("BEFORE TRY"); try { input = new Scanner(client.getInputStream()); output = new PrintWriter(client.getOutputStream(), true); } catch(IOException io) { System.out.println("Client Handler not set up properly"); }}public void run(){ // recieve request from the server String request = input.nextLine(); System.out.println(request); // check the request while(!request.equals("close")) { // do whatever the user wants to do if (request.equals("get_inbox")) { System.out.println("INSIDE INBOX REQUEST"); } else if (request.equals("send_email")) { System.out.println("INSIDE SEND EMAIL REQUEST"); } request = input.nextLine(); // get new request from server } // end the client connection try { System.out.println("Ending connection"); client.close(); } catch(IOException io) { System.out.println("Coulnd't close connection"); }}And this is my error logat javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)at javafx.event.Event.fireEvent(Event.java:198)at javafx.scene.Node.fireEvent(Node.java:8413)at javafx.scene.control.Button.fire(Button.java:185)at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)at javafx.event.Event.fireEvent(Event.java:198)at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run( GlassViewEventHandler.java:381)at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run( GlassViewEventHandler.java:295)at java.security.AccessController.doPrivileged(Native Method)at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354 (GlassViewEventHandler.java:417)at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolki t.java:389)at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewE ventHandler.java:416)at com.sun.glass.ui.View.handleMouseEvent(View.java:555)at com.sun.glass.ui.View.notifyMouse(View.java:937)Caused by: java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)... 45 moreCaused by: java.lang.NullPointerExceptionat Client.validateUsername(Client.java:112)at Client.loginButton(Client.java:99)... 55 morWhat I have tried:I tried to find the problem but sadly any code I tried failed. 解决方案 ControllerMethodEventHandler.handle(FXMLLoader.java:1657)at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)at javafx.event.Event.fireEvent(Event.java:198)at javafx.scene.Node.fireEvent(Node.java:8413)at javafx.scene.control.Button.fire(Button.java:185)at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)at com.sun.javafx.scene.control.skin.BehaviorSkinBase1.handle(BehaviorSkinBase.java:96)at com.sun.javafx.scene.control.skin.BehaviorSkinBase1.handle(BehaviorSkinBase.java:89)at com.sun.javafx.event.CompositeEventHandler 这篇关于为什么我的printwriter会抛出nullpointer错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-11 14:46