I have a Class Sample and I call the method calcValues in my main class. But if I call calcValues, it throws a Null Pointer Exeption. But I do not know why...
Here is the code:
Class Sample:
public List<Float> calcValues(List<Float> inputValues)
{
List<Float> outValues = new ArrayList<>();
for (Float value : inputValues) //causes the error
{
SensorDataResult res = this.mySensorData.computeAverage(value);
System.out.print("Ergebnis: ");
System.out.print(res);
if(res != null)
{
// TODO Maybe check for Alarms
outValues.add(res.getValue());
}
}
return outValues;
}
Class Main:
public static void main(String[] args)
{
Sample newSample = new Sample();
List<Float> inputValues = new ArrayList<Float>();
inputValues.add(10.0f);
newSample.calcValues(inputValues); //causes the error in main class
}
Why does this method (calcValues) throw an error when I call it?
The StackTrace:
Exception in thread "main" java.lang.NullPointerException at at.axtesys.idr.Sample.calcValues(Sample.java:29) at at.axtesys.idr.TCPServer.main(TCPServer.java:24)