What is up with the error Error: Could not find or load main class
in Netbeans 8.0.2 with Java 8?
From seemingly nowhere, I got error when I tried to execute a cleaned-and-built .jar
file from desktop after copying from dist
folder. This has worked for years.
But I got error about java JNI file. It said to compile with -Xlint:deprecation. I did and then I deleted the offending method, which wasn't used anyway.
Then I got the Could not find or load main class
error.
I found this SO thread. A user said at a point well down the page that he had just changed to Java 8. Me, too.
He said he changed back to 7 then back to 8 and the problem went away.
So I changed Source\Binary format
to JAVA 7
and got errors that require Java 8, so I changed Source\Binary format
to JAVA 8
.
After clean and build, no more errors.
I didn't change my code; I didn't change class path.
What exactly is going on? Is it Netbeans 8 or Java 8? It's a pretty quirky workaround.
Here's my DOS path:
C:\Users\Dov>path
PATH=C:\ProgramData\Oracle\Java\javapath;C:\Program Files\Common Files\Microsoft
Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Window
s Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System
32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Com
mon Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Pr
ogram Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Co
mmon Files\Roxio Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio
Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0
\DLLShared\;C:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\S
kype\Phone\
Here's what Java control panel tells me about Runtime Environment Settings for both user and system:
Platform Product Location Path Enabled
1.8 1.8.0_51 http://java.sun.com/products/autodl/j2se C:\Program Files\Java\jre1.8.0_51\bin\javaw.exe true
I don't know what I did to cause the problems but I don't want them occurring again. It took many minutes of stress to get back to working program.
Should I add either or both of the following to my DOS path?
C:\Program Files\Java\jdk1.8.0_51
C:\Program Files\Java\jre1.8.0_51
Should I change classpath? Where and how?