So, here's what I have written on my code. This is the declaration part of the code (written in JAVA).
private class DataStructure{
private VoltageMsg[] voltageMsg;
public DataStructure()
{
this.voltageMsg = new VoltageMsg[VOLTAGE_CH];
}
private class VoltageMsg{
private int Decimal;
private int Integer;
private int ch;
public void setter(int Decimal, int Integer, int ch){
this.Decimal = Decimal;
this.Integer = Integer;
this.ch = ch;
}
}
}
VOLTAGE_CH is constant by the way declared in certain integer value. I tried to use the class like this,
private DataStructure datas;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
datas = new DataStructure();
}
and here's the part when fatal exception happened.
datas.voltageMsg[0].setter(1,2,3);
here's the specific message that I copied from logcat.
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.wise.ksj.kitms_monitoring_device.DeviceStatus$DataStructure$VoltageMsg.setter(int, int, int)' on a null object reference
What did I do wrong? Can I not allocate memory dynamically inside of the constructor like I did? Is that why it keeps showing me this fatal exception? As you can probably guess by now, I'm pretty new to these whole software engineering/programming stuff. Any help would be appreciated. Thank you very much for your time.