Skip to content
Sign upLog in
← Back to Community
Java error
Profile icon
Bunnytoes

I am learning java and I decided to convert my bool quiz game that I made in c#, in java. It is almost done, but it says this error: javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main Error: Main method not found in class Main, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
please help me fix it.
the full code is

import java.util.Scanner; public class Main { static boolean questions; static int points; public static void Main (String[] args) { Start(); } public static void Start () { System.out.print("\033[H\033[2J"); System.out.flush(); Scanner stuff = new Scanner(System.in); System.out.print("Do you want to play my true or false game?(answer true or false)"); boolean quiz = stuff.nextBoolean(); if (quiz == true) { Quiz(); } if (quiz == false) { Start(); } } public static void Quiz () { Scanner Console = new Scanner(System.in); System.out.print("The Big Apple is a nickname given to Washington D.C in 1971."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Wrong answer, this is for new york"); } if (questions == false) { System.out.print("Correct answer"); points += 1; } System.out.print("Muddy York is a nickname for New York in the Winter."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Wrong answer, this is for toronto"); } if (questions == false) { System.out.print("Correct answer"); points += 1; } System.out.print("Peanuts are not nuts"); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Correct answer"); points += 1; } if (questions == false) { System.out.print("Wrong answer, they are considered lentils"); } System.out.print("Electrons move faster than the speed of light."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Wrong answer, they have mass so no"); } if (questions == false) { System.out.print("Correct answer"); points += 1; } System.out.print("Janet Jackson performed at halftime of Super Bowl LV."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Wrong answer, The Weeknd did"); } if (questions == false) { System.out.print("Correct answer"); points += 1; } System.out.print("The film Moneyball is based on a true story."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Correct answer"); points += 1; } if (questions == false) { System.out.print("Wrong answer, it is"); } System.out.print("Emus can't fly"); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Correct answer"); points += 1; } if (questions == false) { System.out.print("Wrong answer, emus are a flightless bird"); } System.out.print("Light travels in a straight line."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Correct answer"); points += 1; } if (questions == false) { System.out.print("Wrong answer, it does but objects can change it's path"); } System.out.print("The Mona Liza was stolen from the Louvre in 1913."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Wrong answer, it was stolen in 1911 and returned in 1913"); } if (questions == false) { System.out.print("Correct answer"); points += 1; } System.out.print("Copyrights don't depreciate over time."); questions = Console.nextBoolean(); if (questions == true) { System.out.print("Wrong answer, they do"); } if (questions == false) { System.out.print("Correct answer"); points += 1; } int score = points * 10; System.out.print("You got" + score + "percent of the questions correct"); } }
Answered by SixBeeps [earned 5 cycles]
View Answer
Voters
Profile icon
Bunnytoes
Comments
hotnewtop
Profile icon
SixBeeps

Read the error.

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

Then look at your code.

public static void Main (String[] args)

See something wrong?

Profile icon
Bunnytoes

@SixBeeps
I tried that yesterday but now it works!Thanks

Profile icon
NISRIENA-BINTI

public class Dadu46 {
public static void main(String[] args) {
int i;
Scanner scanner=new Scanner(System.in);
boolean flag=true;
do{
for (i = 1;i<=20;i++){
System.out.print((int)((Math.random() * 6) + 1) +");
}
System.out.println();
System.out.println("------------------------------------");
System.out.println("Taip ya untuk teruskan.Tidak untuk henti");
if(Scanner.next().equals("ya")){
flag=true;
}else{
flag=false;
}
}while(flag);
}
}

Profile icon
AaronPhilip

Try public static void main(String args[]) on Line 6

Profile icon
AaronPhilip

I forked it and tried it after the change i mentioned above, works fine