I'm trying to use object oriented design and it's a bit confusing. Let's say I have 3 separate objects
public class Tool{
String name;
Float weight;
}
public class Drawer{
String name;
Tool[] tool;
}
public class Toolbox{
String name;
Drawer[] drawer;
public void setDrawers(String[] drawers) {
for(int i = 0; i < drawers.length; i++) {
drawer[i].name = drawers[i];
}
}
}
So a Tool has a String and Float. Drawer has a String and an array of Tools. Toolbox has a String and array of Drawers.
So let's say in my main code I say...
Toolbox myBox = new Toolbox();
myBox.setDrawers(drawers);
I'm getting null pointer issues. What's the proper way to instantiate everything if I want to instantiate a toolbox? Each class is in a separate Java file is this ok, or should they be in one file? Since all classes are in the same app do I need to use the import statement? What would my Constructors look like? Is there anything else I'm missing? Thanks for the help.
Please do not mark this as a duplicate of the "null pointer" question. That does not address objects that contain arrays of other objects and how to instantiate everything.