NullPointerException in stream AWT-EventQueue-0 (file. <Init>)

I am trying to teach myself Java Networking. I tried to write a small WebChat application and it works fine when I try to run it in Eclipse, but when I try to run it in Debug mode, I keep getting this error:

Thread [AWT-EventQueue-0] (Suspended (exception NullPointerException)) owns: Object (id=39) File.<init>(String) line: 251 LoadNativeBundleAction.run() line: 79 AccessController.doPrivileged(PrivilegedExceptionAction<T>) line: not available [native method] MacOSXResourceBundle.getMacResourceBundle(String, String) line: 48 MacOSXResourceBundle.getMacResourceBundle(String) line: 43 AquaLookAndFeel.initResourceBundle(UIDefaults) line: 249 AquaLookAndFeel.initComponentDefaults(UIDefaults) line: 264 AquaLookAndFeel.getDefaults() line: 231 UIManager.setLookAndFeel(LookAndFeel) line: 536 UIManager.setLookAndFeel(String) line: 580 UIManager.initializeDefaultLAF(Properties) line: 1345 UIManager.initialize() line: 1455 UIManager.maybeInitialize() line: 1422 UIManager.getUI(JComponent) line: 1003 JPanel.updateUI() line: 126 JPanel.<init>(LayoutManager, boolean) line: 86 JPanel.<init>(boolean) line: 109 JPanel.<init>() line: 117 JRootPane.createGlassPane() line: 545 JRootPane.<init>() line: 365 Login(JFrame).createRootPane() line: 277 Login(JFrame).frameInit() line: 258 Login(JFrame).<init>() line: 181 Login.<init>() line: 28 Login$2.run() line: 111 InvocationEvent.dispatch() line: 251 EventQueue.dispatchEventImpl(AWTEvent, Object) line: 727 EventQueue.access$200(EventQueue, AWTEvent, Object) line: 103 EventQueue$3.run() line: 688 EventQueue$3.run() line: 686 AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method] ProtectionDomain$1.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 76 EventQueue.dispatchEvent(AWTEvent) line: 697 EventDispatchThread.pumpOneEventForFilters(int) line: 242 EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 161 EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 150 EventDispatchThread.pumpEvents(int, Conditional) line: 146 EventDispatchThread.pumpEvents(Conditional) line: 138 EventDispatchThread.run() line: 91 

I tried to fix it, but I failed many times ...

This is my code:

 package tk.kaes3kuch3n.webchat; import java.awt.EventQueue; public class Login extends JFrame { private static final long serialVersionUID = 1L; private JPanel contentPane; private JTextField txtName; private JTextField txtAddress; private JLabel lblIp; private JTextField txtPort; private JLabel lblPort; private JLabel lblBspIp; private JLabel lblBspPort; public Login() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { e.printStackTrace(); } setResizable(false); setTitle("Chat Login"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(250, 400); setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); //Username JLabel lblUsername = new JLabel("Username:"); lblUsername.setBounds(89, 25, 71, 16); contentPane.add(lblUsername); txtName = new JTextField(); txtName.setBounds(25, 45, 200, 28); contentPane.add(txtName); txtName.setColumns(10); //IP-Address lblIp = new JLabel("IP-Adresse:"); lblIp.setBounds(84, 100, 81, 16); contentPane.add(lblIp); txtAddress = new JTextField(); txtAddress.setBounds(25, 120, 200, 28); contentPane.add(txtAddress); txtAddress.setColumns(10); lblBspIp = new JLabel("(zB 127.0.0.1)"); lblBspIp.setBounds(78, 150, 94, 16); contentPane.add(lblBspIp); //Port lblPort = new JLabel("Port:"); lblPort.setBounds(106, 200, 38, 16); contentPane.add(lblPort); txtPort = new JTextField(); txtPort.setBounds(25, 220, 200, 28); contentPane.add(txtPort); txtPort.setColumns(10); lblBspPort = new JLabel("(zB 55656)"); lblBspPort.setBounds(84, 250, 81, 16); contentPane.add(lblBspPort); //Login-Button JButton btnLogin = new JButton("Login"); btnLogin.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String name = txtName.getText(); String address = txtAddress.getText(); int port = Integer.parseInt(txtPort.getText()); login(name, address, port); } }); btnLogin.setBounds(66, 325, 117, 29); contentPane.add(btnLogin); this.getRootPane().setDefaultButton(btnLogin); } private void login(String user, String address, int port) { dispose(); System.out.println("User: " + user + "\nIP-Adresse: " + address + "\nPort: " + port); new Client(user, address, port); } public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Login frame = new Login(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } } 
+6
source share
1 answer

Ok, I tried it now on Windows and everything works fine. There is an error in OS X.

-1
source

Source: https://habr.com/ru/post/979784/


All Articles