I'm trying to set a Date (highestNumber) with a long (highest) but it throws a NullPointer exception, I can't figure out why.
public static Date highestNumber = null;
long highest = 0;
for (int x = 0;x <numberofData - 2;x++){
long first = Array.Stop.get(x).getTime();
long next = Array.Stop.get(x+1).getTime();
if(x==0){highest = first;}
if (highest < next){
highest = next;
}
}
highestNumber.setTime(highest);
Exception is being thrown on the setTime() line. highest gets a valid value of 1523328768914
Error: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.Date.setTime(long)' on a null object reference
Edit: I don't feel like this is a duplicate of "What is a nullpointerexception since i didn't realise a Date had to be initiaized. I thought it was just a variable like a string.