The local variable n may not have been initialized

后端 未结 4 1309
长发绾君心
长发绾君心 2021-01-27 23:35
import View.UI;
public class App {
UI m;    
public static void main(String [] args){
    System.out.println(\"Hello\");
    UI n ;
    n.menu();
}}

Th

4条回答
  •  猫巷女王i
    2021-01-28 00:28

    As it is, calling n.menu() will cause a NullPointerException since you never assign anything to it.

    You will need to do something like so: UI n = new ... or UI n = someObject.

提交回复
热议问题