I'm trying to design a pretty simple simulation civilization game for school. Right now I'm trying to make it so when you click this button on the control bar you make a new hut instance. I will put error report below and code where the error occurs.
Error Report:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at controls.Sidebar.clickBuildHut(Sidebar.java:102)
at screen_window.Game_Window.mouseClicked(Game_Window.java:248)
at java.awt.Component.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Window.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Code where error occurs:
public void newHut() {
numOfHuts++;
hut[numOfHuts] = new Hut(mouseX, mouseY, 0, numOfHuts);
}
Hut declaration at top of class:
Hut[] hut = new Hut[9999];
int numOfHuts;
Sidebar.clickBuildHut method:
public boolean clickBuildHut(int mouseX, int mouseY){
if (viewConstruction){
int topLeftX = x + 2;
int topLeftY = y + 50 - 14;
int selectionWidth = width - 10;
int selectionHeight = 17;
for (int i = 0; i <= width; i++) {
for (int h = 0; h <= height; h++) {
if (mouseX == topLeftX + i && mouseY == topLeftY + h) {
first_map.setEditMode(true);
game_window.newHut();
return true;
}
}
}
}
return false;
}
first_map.setEditMode:
public void setEditMode(boolean editMode) {
this.editMode = editMode;
}
Although I don't think that this is the problem because when this is switched to true I see the picture change correctly. If you want me to give you more information on this I can but, I don't think that it would be of any use since it isn't where the problem lies.