0
 public Interface(Application referenceApplication) {
    final JFrame clientWindow = new JFrame("Air Traffic Information");
    // Initialise the Search Parameter Selector:
    final DefaultComboBoxModel<String> parameters = new DefaultComboBoxModel<>();
    parameters.addElement(SearchCategories.NAME.toString());
    parameters.addElement(SearchCategories.IATA.toString());
    parameters.addElement(SearchCategories.ICAO.toString());
    airportParameter.setModel(parameters);
    // Initialise the Table:
    guiTable = new UniversalTableModel();
    table.setModel(guiTable);
    // Clear Search Box on Click:
    airportField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            if (!airportField.getForeground().equals(Color.BLACK)) {
                super.focusGained(e);
                airportField.setText("");
                airportField.setForeground(Color.BLACK);
            }
        }
    });
    // Attempt to Safely Disconnect from Server when Window is Closed:
    clientWindow.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            referenceApplication.disconnectServer();
            System.exit(0);
        }
    });
    // Display and Re-Size Contents:
    clientWindow.add(mainPanel);
    clientWindow.setVisible(true);
    clientWindow.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    clientWindow.pack();
}

Getting error:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "location" is null

I have made sure that images are in the right place.

Code line where console is showing the error is:

final JFrame clientWindow = new JFrame("Air Traffic Information");

in javax.swing

public ImageIcon (URL location) {
    this(location, location.toExternalForm());
}

in java.lang

public class NullPointerException extends RuntimeException {
@java.io.Serial
private static final long serialVersionUID = 5162710183389028792L;

Screenshot of directory

Full error in console:

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "location" is null
 at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:234)
 at client.Interface.$$$setupUI$$$(Interface.java)
 at client.Interface.<init>(Interface.java:48)
 at client.Application.main(Application.java:313)
Holger
  • 285,553
  • 42
  • 434
  • 765
  • The error points to a `toExternalForm()` call so it can't be that JFrame row. Please provide the code around the failing location. – akarnokd Jun 21 '22 at 07:31
  • @akarnokd I have added more details and as you stated I was also sure there is nothing wrong with the main code. The errors seems to be directing me to the swing library – Mandy Lores Jun 21 '22 at 07:53
  • What are on these lines? Interface.java:48 Application.java:313 ? – akarnokd Jun 21 '22 at 07:56
  • @akarnokd Interface.java:48 final JFrame clientWindow = new JFrame("Air Traffic Information"); as mentioned above; Application.java:313 = clientApplication.guiWindow = new Interface(clientApplication); – Mandy Lores Jun 21 '22 at 08:03
  • That makes no sense. Usually there is a `getResource` call which can't find the image, hence the null. Are you using some kind of UI binding mechanism? Check what icon it references and see if you have it in the right location, including if it starts with "/" or not. – akarnokd Jun 21 '22 at 08:06

0 Answers0