Reputation: 87
Trying to write a program to calculate my GPA for me, and I keep receiving this message when I try to run the prototype:
java.lang.NoSuchMethodError: main
Exception in thread "main"
Here's the code:
package orange;
import java.util.Scanner;
public class plums{
String philosophy, econ, french, fye, marine, stats;
public void main(String args[]){
Scanner gpa = new Scanner(System.in);
System.out.println("Philosophy Grade: ");
philosophy = gpa.nextLine();
System.out.println("Econ grade: ");
econ = gpa.nextLine();
System.out.println("French Grade: ");
french = gpa.nextLine();
System.out.println("FYE Grade: ");
fye = gpa.nextLine();
System.out.println("Marine grade: ");
marine = gpa.nextLine();
System.out.println("STATs Grade: ");
stats = gpa.nextLine();
}
public void main(double[] args) {
gpa philGrade = new gpa(4);
if (philosophy.equals("a") )
gpa.philGrade = 4;
else if (philosophy.equals("a-"))
gpa.philGrade = 3.7;
else if (philosophy.equals("b+"))
gpa.philGrade = 3.3;
else if (philosophy.equals("b"))
gpa.philGrade = 3;
else if (philosophy.equals("b-"))
gpa.philGrade = 2.7;
else if (philosophy.equals("c+"))
gpa.philGrade = 2.3;
else if (philosophy.equals("c"))
gpa.philGrade = 2;
else if (philosophy.equals("c-"))
gpa.philGrade = 1.7;
else if (philosophy.equals("d+"))
gpa.philGrade = 1.3;
else if (philosophy.equals("d"))
gpa.philGrade = 1;
else if (philosophy.equals("d-"))
gpa.philGrade = .7;
else if (philosophy.equals("f"))
gpa.philGrade = 0;
else
System.out.println("y u do dis??");
This is for one class and here's the other class:
package orange;
public class gpa {
public static double philGrade;
public gpa(double grade1){
philGrade=grade1;
}
public void lines(){
System.out.println(gpa.philGrade);
}
}
Upvotes: 0
Views: 107
Reputation: 1344
Your main
method must be declared as public static.
Declaration of main method:
public static void main (String [] args)
The main
method is declared public as it called from outside, i.e by JVM.
And it is declared as static as it is called before the instantiation of object of class (it is the first point of execution of code.)
Upvotes: 1
Reputation: 7804
public static void main(String[] args)
is the entry point for any Java program. When you execute a java file, JVM looks for this method to start execution. In your case, it is unable to find it and hence it throws java.lang.NoSuchMethodError: main
error.
Solution:
Added static
modifier to your method : public void main(String args[])
Upvotes: 0
Reputation: 4476
Make the main method static as shown below.
public static void main(String args[]){
Upvotes: 0
Reputation: 41975
public static void main(String args[]){
...
}
You are missing static
Upvotes: 0