My Code has a problem, either if my first void is static or not i get a error that i cant seem to fix.
This is the error i get if the void is static
Java Compiler By Noj
All underpreciated java will soon apear
All errors within java files will soon apear
RPGmain.java:29: non-static method mainmenu(java.lang.String) cannot be referenc
ed from a static context
mainmenu(playername);
^
1 error
Press any key to continue . . .
if its not static it compiles fine, but it wont run i get this error when i attempt to run the code.
Exception in thread "main" java.lang.NoSuchMethodError: main
Press any key to continue . . .
This is my code.
import java.util.Scanner;
public class RPGmain {
public int hp = 30;
public int str = 25;
public int def = 20;
public int intel = 20;
public int bronzecoins = 50;
public int silvercoins = 25;
public int goldcoin = 1;
public int level = 1;
public int exp = '1';
public int makerestart = 1;
public void Openning (String args[]) {
System.out.println("Beware this game is not saveable");
System.out.println("What is your name?");
Scanner scan = new Scanner(System.in);
String playername = scan.next();
System.out.println("hello " + playername);
System.out.println("Welcome to Text RPG");
mainmenu(playername);
}
public void mainmenu (String playername) {
while (makerestart <= 200000);
{
makerestart += 2;
System.out.println("What would you like to do " + playername + "?");
System.out.println("Type in help if your new");
Scanner whatsnext = new Scanner(System.in);
String nextaction = whatsnext.next();
if(nextaction == "stats"); {
System.out.println("hitpoints: " + hp);
System.out.println("Strength: " + str);
System.out.println("Defence: " + def);
System.out.println("intelligeance: " + intel);
System.out.println("Bronze: " + bronzecoins);
System.out.println("Silver: " + silvercoins);
System.out.println("Gold: " + goldcoin);
System.out.println("Combat Level: " + level);
}
}
}
}
only part that really matter about the error is the top area so i removed a bit from the bottom (the rest was all more if(nextaction == "text") anyway)
i was told making the first void static fixes the
Exception in thread "main" java.lang.NoSuchMethodError: main
problem, only way i had that work and the code compile is when i added in a empty void
something like
public static void empty (String args[]) {
}