Javac does not recognize the Error. Perhaps it's just an Eclipse thing? I ran javac on console. No error from that. The code just runs.
--- Update ---
Okay, I managed to fix the NULL problem regarding the Status option in pmenu. Here is my code now:
The error on class Player persist however.
EDIT:
NEVERMIND! The Class Player error was because I did not close the Roleplaygame code xD!
However, can you look at my code and see if there is any logic error? Or something that I should not do?
import java.util.Scanner;
class Player {
private String name;
private String gender;
private String hcolor;
private String ecolor;
private String size;
private String height;
private String place;
public void setname(String name)
{
this.name = name;
}
public void setgender (String gender)
{
this.gender = gender;
}
public void sethcolor (String hcolor)
{
this.hcolor=hcolor;
}
public void setecolor (String ecolor)
{
this.ecolor=ecolor;
}
public void setsize (String size)
{
this.size = size;
}
public void setheight (String height)
{
this.height=height;
}
public void setplace (String place)
{
this.place=place;
}
public String getname()
{
return name;
}
public String getgender()
{
return gender;
}
public String gethcolor()
{
return hcolor;
}
public String getecolor()
{
return ecolor;
}
public String getsize()
{
return size;
}
public String getheight()
{
return height;
}
public String getplace()
{
return place;
}
public void geteverything()
{
System.out.println("Name: " + getname());
System.out.println("Gender: " + getgender());
System.out.println("Hair Color: " + gethcolor());
System.out.println("Eye Color: " + getecolor());
System.out.println("Size: " + getsize());
System.out.println("Height: " + getheight());
}
}
public class Roleplaygame2 {
public static void main(String[] args) {
Player player1 = new Player();
Scanner scanner = new Scanner (System.in);
System.out.print("Name: ");
String name = scanner.nextLine();
player1.setname(name);
System.out.print("Gender: ");
String gender = scanner.next();
player1.setgender(gender);
System.out.print("Hair Color: ");
String hcolor = scanner.next();
player1.sethcolor(hcolor);
System.out.print("Eye Color: ");
String ecolor = scanner.next();
player1.setecolor(ecolor);
System.out.print("Fat or Skinny: ");
String size = scanner.next();
player1.setsize(size);
System.out.print("Tall or Short: ");
String height = scanner.next();
player1.setheight(height);
System.out.print("Name of the town you are going to: ");
String place = scanner.next();
player1.setplace(place);
System.out.println ("...");
System.out.println ("...");
System.out.println ("Welcome to " + player1.getplace());
pmenu(player1);
}
public static void pmenu(Player player1)
{
Scanner scanner2 = new Scanner (System.in);
System.out.println("--------------------------");
System.out.println("Welcome to " + player1.getplace());
System.out.println("1. Status");
System.out.println("2. Inventory");
System.out.println("3. Talk to NPC: Bob");
System.out.println("4. Store");
System.out.println("What would you like to do?");
int pinput = scanner2.nextInt();
if (pinput==1)
{
player1.geteverything();
pmenu(player1);
}
}
}