java运行错误:Exception in thread "main" java.lang.NullPointerException
错误提示Exceptioninthread"main"java.lang.NullPointerExceptionatGameController.ChangeRoles...
错误提示
Exception in thread "main" java.lang.NullPointerException
at GameController.ChangeRoles(GameController.java:113)
at GameController.PlayGame(GameController.java:35)
at MainDriver.DisplayMainMenu(MainDriver.java:67)
at MainDriver.main(MainDriver.java:14)
Maindriver.java
import java.util.Scanner;
public class MainDriver {
public static Scanner scanInput;
public static void main(String[] args){
scanInput = new Scanner (System.in);
DisplayMainMenu();
scanInput.close();
}//Main
public static void DisplayMainMenu()
{
boolean isMenuRunning = true;
String userInputString = "";
char userInputChar;
word newWord = new word("Hello Word");
while(isMenuRunning){
System.out.println(".................................");
System.out.println("Hangman Main Driver / Test Menu");
System.out.println("1: Add Word");
System.out.println("2: Display Clue");
System.out.println("3: Display Instructiona");
System.out.println("4: Play Game");
System.out.println("0: Quit Game");
System.out.println(".................................");
userInputString = scanInput.nextLine();
if(userInputString.length() == 0){
continue;
}
userInputString = userInputString.toUpperCase();
userInputChar = userInputString.charAt(0);
switch(userInputChar){
case '1':
newWord = new word(GetStringFromUser() );
break;
case '2':
System.out.println("Clue for current word: " + newWord.GetClue() );
break;
case '3':
System.out.println("INSTRUCTIONS FEATURE COMING SOON");
break;
case '4':
GameController controller = new GameController();
controller.PlayGame();
break;
case '0':
isMenuRunning = false;
break;
default:
System.out.println("Please enter a valid option");
break;
}
}//while
}
private static String GetStringFromUser(){
String tempString = "";
System.out.println("Please enter a word(s) to guess");
tempString = scanInput.nextLine();
return tempString;
}
}//MainDriver
因为字数限制,gamecontroller只能导成图片了,而且还分了两行,比较费眼请见谅。。 展开
Exception in thread "main" java.lang.NullPointerException
at GameController.ChangeRoles(GameController.java:113)
at GameController.PlayGame(GameController.java:35)
at MainDriver.DisplayMainMenu(MainDriver.java:67)
at MainDriver.main(MainDriver.java:14)
Maindriver.java
import java.util.Scanner;
public class MainDriver {
public static Scanner scanInput;
public static void main(String[] args){
scanInput = new Scanner (System.in);
DisplayMainMenu();
scanInput.close();
}//Main
public static void DisplayMainMenu()
{
boolean isMenuRunning = true;
String userInputString = "";
char userInputChar;
word newWord = new word("Hello Word");
while(isMenuRunning){
System.out.println(".................................");
System.out.println("Hangman Main Driver / Test Menu");
System.out.println("1: Add Word");
System.out.println("2: Display Clue");
System.out.println("3: Display Instructiona");
System.out.println("4: Play Game");
System.out.println("0: Quit Game");
System.out.println(".................................");
userInputString = scanInput.nextLine();
if(userInputString.length() == 0){
continue;
}
userInputString = userInputString.toUpperCase();
userInputChar = userInputString.charAt(0);
switch(userInputChar){
case '1':
newWord = new word(GetStringFromUser() );
break;
case '2':
System.out.println("Clue for current word: " + newWord.GetClue() );
break;
case '3':
System.out.println("INSTRUCTIONS FEATURE COMING SOON");
break;
case '4':
GameController controller = new GameController();
controller.PlayGame();
break;
case '0':
isMenuRunning = false;
break;
default:
System.out.println("Please enter a valid option");
break;
}
}//while
}
private static String GetStringFromUser(){
String tempString = "";
System.out.println("Please enter a word(s) to guess");
tempString = scanInput.nextLine();
return tempString;
}
}//MainDriver
因为字数限制,gamecontroller只能导成图片了,而且还分了两行,比较费眼请见谅。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询