No Main class found in NetBeans

前端 未结 16 2444
时光说笑
时光说笑 2020-11-30 08:32

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

相关标签:
16条回答
  • 2020-11-30 09:19
    1. Right click on your Project in the project explorer
    2. Click on properties
    3. Click on Run
    4. Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
    5. Click OK.
    6. Run Project :)

    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)

    0 讨论(0)
  • 2020-11-30 09:19
    import java.util.Scanner;
    public class FarenheitToCelsius{
        public static void main(String[]args){
         Scanner input= new Scanner(System.in);
         System.out.println("Enter Degree in Farenheit:");
         double Farenheit=input.nextDouble();
         //convert farenheit to celsius
         double celsuis=(5.0/9)*(farenheit 32);
         system.out.println("Farenheit"+farenheit+"is"+celsius+"in celsius")
                 {
    
    0 讨论(0)
  • 2020-11-30 09:21

    There could be a couple of things going wrong in this situation (assuming that you had code after your example and didn't just leave your code unbracketed).

    First off, if you are running your entire project and not just the current file, make sure your project is the main project and the main class of the project is set to the correct file.

    Otherwise, I have seen classmates with their code being fine but they still had this same problem. Sometimes, in Netbeans, a simple fix is to:

    1. Copy your current code (or back it up in a different location)
    2. Delete your current file
    3. Create a new main class in your project (you can name it the old one)
    4. Paste your code back in

    If this doesn't work then try to clear the Netbeans cache, and if all else fails, then just do a clean un-installation and re-installation of Netbeans.

    0 讨论(0)
  • 2020-11-30 09:22

    I had the same problem in Eclipse, so maybe what I did to resolve it can help you. In the project properties I had to set the launch configurations to the file that contains the main-method (I don't know why it wasn't set to the right file automatically).

    0 讨论(0)
  • 2020-11-30 09:23

    if all that is your code you forgot to close the main method

    everything else sounds good to me

    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(); 
    }}
    

    try that

    0 讨论(0)
  • 2020-11-30 09:28

    If the advice to add the closing braces work, I suggest adding indentation to your code so every closing brace is on a spaced separately, i.e.:

    public class LuisRp3 {
    
        public static void main(String[] args) throws FileNotFoundException  {
    
        // stuff
    
        }
    }
    

    This just helps with readability.

    If, on the other hand, you just forgot to copy the closing braces in your code, or the above suggestion doesn't work: open up the configuration and see if you can manually set the main class. I'm afraid I haven't used NetBeans much, so I can't help you with where that option is. My best guess is under "Run Configuration", or something like that.

    Edit: See peeskillet's answer if adding closing braces doesn't work.

    0 讨论(0)
提交回复
热议问题