-1

Error:

Error: Main method not found in class app, please define the main method as:
   public static void main(String[] args)

Code:

class app
{
    public static void main(String[] args) {
        double accounts[];
        accounts=new double[100];
        accounts[2]=1225.33;
        System.out.println("Account 2 is overdue by $"+accounts[2]);
    }
}

I am using EditPlus to run and execute this program.

2 Answers2

0

If you are trying to run a class you need the main method. Add the main method to the class and put the code you are trying to execute inside the main method and it should execute. Also post the code you do have so it's easier for us to understand what you are trying to do.

public static void main(String[] args) {
   //code goes here
}
brso05
  • 13,142
  • 2
  • 21
  • 40
  • I have already written main method in my code but i don't know why this error showing again and again. – sipra mahalik Sep 22 '14 at 15:00
  • I am writing a very simple code if you wants to see it i can post it here. – sipra mahalik Sep 22 '14 at 15:01
  • class app { public static void main(String[] args) { double accounts[]; accounts=new double[100]; accounts[2]=1225.33; System.out.println("Account 2 is overdue by $"+accounts[2]); } } – sipra mahalik Sep 22 '14 at 15:03
  • Edit it into your opening post @sipramahalik – But I'm Not A Wrapper Class Sep 22 '14 at 15:04
  • There is nothing wrong with your code how are you executing eclipse, netbeans, command prompt...? – brso05 Sep 22 '14 at 15:04
  • How are you compiling and executing the code? Command Prompt? Because there is nothing wrong with your code have you tried compiling and running? Because that editor may be saying there is something wrong even though there isn't. – brso05 Sep 22 '14 at 15:08
0

There is either something broken about the tools you are using, or the process you are using. (For example, you might have made a mistake with your classpath.)

At any rate, your program works for me, as demonstrated by the following:

[steve@newbox tmp]$ cat > app.java
class app
{
    public static void main(String[] args) {
        double accounts[];
        accounts=new double[100];
        accounts[2]=1225.33;
        System.out.println("Account 2 is overdue by $"+accounts[2]);
    }
}


[steve@newbox tmp]$ javac app.java 
[steve@newbox tmp]$ java app
Account 2 is overdue by $1225.33
[steve@newbox tmp]$

For the record, this is with Java 8 tools ... and I haven't set the CLASS_PATH environment variable. (Hence, java and javac will just be using the current directory as the classpath.)


The only other possibility I can think of is that your original code has a nasty homoglyph in (maybe) the main identifier, that causes the java command to not see the method. There is a chance that StackOverflow will silently "fix" homographs in Questions and Answers. (It certainly seems to "fix" dodgy control codes.)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216