I have been working on an assignment for my class in programming. I am working with NetBeans. I finished my project and it worked fine. I am getting a message that says "No main class found" when I try to run it. Here is some of the code with the main:
package luisrp3; import java.io.FileNotFoundException; import java.io.PrintStream; public class LuisRp3 { public static void main(String[] args) throws FileNotFoundException { java.io.File newFile = new java.io.File("LuisRamosp4.txt"); if (newFile.exists()) { newFile.delete(); } System.setOut(new PrintStream(newFile)); Guitar guitar = new Guitar();
I posted this before but had a couple issues. i have fixed the others and now have just this one remaining. Any advice will be greatly appreciated.
To change the main class being used, go to the File menu and choose Project Properties. This dialog gives all the options that can be changed in a NetBeans project. Click on the Run category. On this page, there is a Main-Class option.
Make sure all files are saved first. If you try to run a program where the class containing the main method has not been saved, this can happen. Right-click on the project name (in the Projects explorer), then select Properties > Run - and then make sure the main class is selected there.
Right-click the user name package and select New -> Java Main Class... Name your class Menu . Run the project. You will be prompted to select the main class.
If you just want to run the file, right click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)
Also, for others out there with a slightly different problem where Netbeans will not find the class when you want when doing a browse from "main classes dialog window".
It could be that your main method does have the proper signature. In my case I forgot the args.
example: public static void main(String[] args)
The modifiers public and static can be written in either order (public static or static public), but the convention is to use public static as shown above.
Args: You can name the argument anything you want, but most programmers choose "args" or "argv".
Read more here: http://docs.oracle.com/javase/tutorial/getStarted/application/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With