0

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?

Community
  • 1
  • 1
DSlomer64
  • 4,234
  • 4
  • 53
  • 88

1 Answers1

1

Error: Could not find or load main class

As far as I know, the main method of the class specified in the Main-Class header is executed in both java 7 and 8 in jar files. I don't see why changing from java 7 to 8 would break anything even with mismatched compilers and runtime (although you will probably run into other issues, as you mentioned you did).

You can see which version of java and javac you have by typing:

java -version

javac -version

If you feel the need to upgrade you can change your path

  1. Go to Control Panel --> System and Security --> System

  2. Click Advanced system settings

  3. Click Environment Variables

  4. In the System Variables area, locate the Path variable, highlight it and click.

  5. Make the required changes.

If you have windows 8 or 10 (maybe even 7) you can just search for path and click edit system environment variables and that will take you right to step 4.

mattg123
  • 23
  • 3