import View.UI;
public class App {
UI m;
public static void main(String [] args){
System.out.println(\"Hello\");
UI n ;
n.menu();
}}
Th
public static void main(String [] args){
System.out.println("Hello");
UI n =AssignUIOBjectHere ;
n.menu();
}}
Method's local variables
needs to be initialize, before they are using.
Compiler complaining that you are using a variable which is not yet initialized.
As per language specification
Every variable in a program must have a value before its value is used:
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.
You have to create an instance of UI, such as; UI n = new UI();
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
.