Error: Could not find or load main class main.Main


#1

I can't get my program to run. I recently copied over the files then made a few unimportant changes on another computer, then copied them back and tried to run the program, but I got this error message: Error: "Could not find or load main class main.Main"



Interestingly, the program WILL compile, and it will even run when I run it manually with "java -jar MyJarFile.jar".



I tried to set the main class by going to the project properties, in the "run" category, then clicked "Browse" next to the Main Class field, and it said that no main classes were found.



More interestingly, when I go to Important Files -> Build file -> run, then right-click and say "Run Target" it works correctly. It just doesn't run correctly when I use the "Run Main Project" button or "Debug Main Project" button.



What am I doing wrong? How do I fix this?


#2

Reading the manual helps. Project Properties->Run->Set main class


#3

As I said, that just says “no main classes were found”.


#4

Just enter the full name of your main class if the UI cannot find it.


#5

That compiles correctly, but then I still can’t run/debug main project.


#6

“on another computer” does that mean you opened the project in another version of NetBeans or that you just edited the files?


#7

Actually what I did was install jMonkeyEngine on another computer on the same network and mapped the Z: drive to the project folder and accessed it that way.


#8

Uhm, are you sure its selected as the main project?


#9

Yes, it looks that way. Here’s a crudely-cropped screenshot:



http://i.imgur.com/7TUVj.png


#10
  1. Clean and build
  2. Save the main class one more time
  3. Close JME
  4. Open JME
  5. Clean and build ones more
  6. Save the main class one more time



    That’s what I do when I have that problem (and I have it often)

    If your problem is equal to mine, it should work after that, just try it out.

#11

That’s slowly working, but it looks like I have to resave every single class in the project. Annoying, but it works.



Thank you very much!


#12

It seems that this problem (and solution) are reproducible. Should I submit a bug report?


#13

How you cause the issue?


#14

OK. Sorry to bump this topic but, I had the same problem yesterday.
I tried to rename the project name (refactoring AntHill to Anthill) and did a Java update. Then, I got the same error.
I think i fixed it (I did fix it) by closing the IDE, renaming the project directory. (You can put a .old on a directory.)
Then, I re-created the project with the corrected name.
Then, I copied back the src dir and the assets dir, test dir, and I think that was all with Windows Explorer.
I started it up and let it do a background scan. (I’ve had background scans take hours after a major rework or mapping my local project to a network drive to match the mapping on my remote computer but, this one didn’t take long.)
Then, it worked.
I hope this helps someone.


#15

Did you tried the tip from normen ?

Project Properties->Run->Set main class


#16

Yes. Same as reported above. It just plane doesn’t come up in the list. Yes, it’s very weird!


#17

What happens if you put your class manually ?
Remember to put the complete package.classname on it.
Also, we are expecting you are using jme on netbeans right ?


#18

Well, as he said, it all worked one minute before - and then it didn’t (after some small changes). We did something that confused it. I didn’t try the complete package name because it had it 10 minutes before.
That said, I use NetBeans/JMonkey and they are fantastic. I guess the background scanning takes place of the ‘classpath’ thing. I’ll make a donation to you guys and to Blender.


#19

If you change the main class name for example, you will have to change manually the run configurations.
Its not jme that is that way, its netbeans…


#20

This worked for me - thx!