Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Main class missing

+5 votes
asked Jan 21, 2022 by NATHAN BERNHARD (170 points)
So I have a program that I am working on and in Main.java, I put a public class Main. I added stuff inside of it, however the console keeps telling me "Error: Could not find or load main class Main. Caused by: java.lang.NoClassDefFoundError: net/codestudent/main/Main (wrong name: Main)" It is very frustrating!  

https://onlinegdb.com/2VQ8_1naf

here is my code.

1 Answer

+1 vote
answered Jan 21, 2022 by Peter Minarik (86,040 points)

I don't really work with Java.

If you remove the

package net.codestudent.main;

from both of your source files your code compiles and runs just fine.

It seems like you need an extra compilation flag for packages (see here for instance), but when I tried to set it up in the top right of the editor, clicking on the gear icon then on the "Extra Compiler Flags", it didn't seem to help.

Again, I'm not a Java guru, not sure what's going on here. If you don't need the package, then you can simply just remove those lines. :)

Unless... When you create a package, it's just a package, like a dll. It is not an executable, just a loadable library and you need something else to load it. So probably your Main should not be part of the package anyway as packages do not have entry points just a list of exposed types, constants, functions, etc.

commented Jan 21, 2022 by NATHAN BERNHARD (170 points)
thank you! this made it so much better:)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...