null pointer exception
in
Programming Questions
•
2 years ago
I'm getting a null pointer exception for this bit of code:
class Menubar
{
private Menu[] Menus;
private int numMenus=0;
//Creates an empty menubar
Menubar() {}
void addMenu (String name)
{
Menus[numMenus]=new Menu(name);
numMenus++;
}
and then this line in draw:
menubar.addMenu("File");
What am I doing wrong? Do I need to declare the size of the Menu array? Is there a way around that?
1