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只能导成图片了,而且还分了两行,比较费眼请见谅。。
展开
 我来答
木有芒果
2016-04-15 · 如果你问我是谁~我会说我叫木有芒果~哈哈
木有芒果
采纳数:112 获赞数:595

向TA提问 私信TA
展开全部
错误提示还是很明显嘛
at GameController.ChangeRoles(GameController.java:113)

去GameController类的113行代码看看到底哪里空了噻,你贴的代码也没有包括GameController嘛
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式