Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OS and java.lang.NullPointerException at java.awt.Window.init(Window.java:497)

Tags:

java

macos

I've been setting up a 2018 MacBook Pro for Java development. It's running Mojave 10.14.1 - just like the older machine I'm migrating from, an early 2013 MacBook Pro. I installed Java 1.8.0_192 and immediately noticed that I could not launch jars or any Java app that had a UI on this mac. I uninstalled and tried each of these: 1.8.0_172, 1.8.0_191, 1.8.0_192, and 11.0.1. I traced the issue further and found a common error:

Caused by: java.lang.NullPointerException
  at java.awt.Window.init(Window.java:497)
  at java.awt.Window.<init>(Window.java:537)
  at java.awt.Frame.<init>(Frame.java:420)
  at java.awt.Frame.<init>(Frame.java:385)
  at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1763)
  at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1838)
  at javax.swing.JWindow.<init>(JWindow.java:187)
  at javax.swing.JWindow.<init>(JWindow.java:139) 

Curious, I launched our Swing-based product and it reported the same error. I googled and found only unanswered posts.

(revising this to be formatted as a question and not a blog post)

What gives?

like image 957
HankNessip Avatar asked Nov 08 '18 21:11

HankNessip


People also ask

How do I fix system error Java Lang NullPointerException?

In Java, the java. lang. NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object. This error can be resolved by using a try-catch block or an if-else condition to check if a reference variable is null before dereferencing it.

What causes Java Lang NullPointerException?

Some of the common reasons for NullPointerException in java programs are: Invoking a method on an object instance but at runtime the object is null. Accessing variables of an object instance that is null at runtime. Throwing null in the program.

What is Java Lang NullPointerException in selenium?

NullPointerException is thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of a null object. Accessing or modifying the field of a null object.


3 Answers

I had the same issue and I found it reported here.

In my case, I was using a docking station for my MacBook Pro and DisplayLink Driver for extended display. This made Jmeter crash.

The workaround was to disconnect my laptop from its docking station and launching the application.

like image 55
Praj Avatar answered Nov 07 '22 01:11

Praj


The solution to this problem was simple, but not immediately obvious.

I dug into the JVM and found that the native code wasn't able to identify a compatible graphics mode from the OS. This results in a null GraphicsConfiguration. That's not good - it causes a NullPointerException in Window.java...guess what line. (Line 497)

I suspected the OS wasn't returning the right information about its graphics setup and then started to suspect the graphics driver. That's when I remembered Macs have parameter RAM (PRAM) and non-volatile RAM (NVRAM).

I zapped the PRAM and NVRAM and now the machine is working fine!

To zap the PRAM and NVRAM:

  1. shut down your mac
  2. restart while holding option+command+P+R
  3. keep holding these until the mac appears to reboot again (the apple logo will appear, disappear, and reappear)

If your mac starts up without the disappearing mac logo, shut it down and retry.

Reset NVRAM or PRAM on your Mac

I hope resetting the PRAM helps others!

like image 40
HankNessip Avatar answered Nov 07 '22 00:11

HankNessip


We have the same issue when trying to open an inhouse Java-based application in conjunction with Dell D6000 docks using DisplayLink software.

As others have suggested disconnecting the Dock then launching the application works after which you can reconnect the dock and move the application to the other screen.

The other way we have managed to get it to work is with the laptop open making the laptop screen the main display this is done in the system prefs in the display settings and moving the white bar to the laptop screen then opening the application.

I think it has been said before when the main display is one run through DisplayLink it can't detect the display so return a null value, even running most recent drivers (24th Aug 2020) this is still the case.

So its workarounds not solutions if you are in the same boat

like image 1
Ben Avatar answered Nov 07 '22 02:11

Ben