The local variable n may not have been initialized

后端 未结 4 1308
长发绾君心
长发绾君心 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条回答
  •  余生分开走
    2021-01-28 00:13

    If you are declaring variables/object inside the method in java you need to initialize it.

    In most simple term,

    In your case its an object which is accessing a method so if you do not initialize it like

    UI n = new UI();
    

    it would give you an NULL pointer exception.

    Hope it helps.

提交回复
热议问题