正如标题所提到的。为什么主类无法调用event.java函数并打印出我想要它打印的消息?我还漏了什么吗非常感谢。
App.java:(主程序)
package com.mainsystem;
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hi");
Event event = new Event();
event.StartGame();
}
}
Event.java (由主程序调用)
package com.mainsystem;
import java.util.Scanner;
public class Event {
Scanner sc = new Scanner(System.in);
public void StartGame() {
System.out.println("Welcome to new World.");
System.out.println("You are now invited to this new world...");
}
}
我的预期结果:
Hi.
Welcome to new World.
You are now invited to this new world...
但现在显示的结果是:
Hi
1条答案
按热度按时间6rqinv9w1#
也许在初始化
Event-Class
时抛出了异常?你也在创建PlayerReaction
和Player
的示例,也许里面有一个NullPointer?为了调试的目的,你可以捕获并打印可能出现在某处的所有异常: