The error is:
java.lang.NullPointerException
at Zentrale.OpenMenu(Zentrale.java:275)
I get a idea behind it that may be a littel bit confusing but anyway
the code works like this:
if the button is clicked it calls the "Zentrale" Object, that isn't implemented in the world,
over the "Spiel" class, that is a subclass of World, to do the method:
OpenMenu(String). The String is used to know wich Menu should open.
Insert() inserts the Objects out of the "UpperMenu" list into the world.
I want to do it like this, becaus it is quite nice to get everything listed up and just shar this list to creat a big amount of objects. This might be an more complicatet way first, but if you have to fill in more menus it is easier to have everything at a spot and listed up.
The problem is the error message tells me to look in line 275 and this line is:
and i can't figure out why it doesn't work.
Here the Insert() code:
Just hope i don't confuse you too much and somebody is able to give me an answer ;).
I want to know where the mistake is.
public void OpenMenu(String Menu)
{
if( Menu == "UpperMenu")
{
if(UpperMenu.isEmpty()==true) // List isn't set up.
{
Button Close = new Button("UpperMenu",2);
Button Option = new Button("UpperMenu",3);
UpperMenu.add(0,Schließen);
UpperMenu.add(1,Optionen);
}
Spiel w = (Spiel)getWorld();
w.Insert(UpperMenu);
}
}w.Insert(UpperMenu);
public void Insert(java.util.ArrayList List)
{
for(int n = 0; n <= List.size(); n++)
{
if( List.get(n) != null)
{
if(List.get(n) == MenuWindow.class)
{
MenuWindow M = (MenuWindow)List.get(n);
addObject(M,M.GiveX(),M.GiveY());
}
if(List.get(n) == Button.class)
{
Button M = (Button)List.get(n);
addObject(M,M.GiveX(),M.GiveY());
}
}
}
}

