Using system time functions causes sketch to not run? ("Target VM failed to initialize")

I’m not sure if this is the correct forum, but I seem to have encountered a major issue in my project. My sketch has started fine so far but suddenly stopped working. Through some basic troubleshooting, I found
the issue is related to any-and-all system time functions (I.E hour(), minute(), and second()). I also tried writing the functions in the exact syntax shown in the documentation, to no avail. Please help if you can. Here’s my code, i’ve included the entirety of the draw function for clarity:

void draw() { 
  
  Current_Time[0] = hour();
  
  // Current_Time[1] = minute();
  
  // Current_Time[2] = second();
  
  

  if (AI_Output != null) {
    
    Output_Alpha = 0;
    
    ShowOutput();
    
  }

  // Initialzation:
  
  if (Splash_Frame < 240) {
    
    Splash_Frame += 1;
    
    Splash_Boot();
    
    print(Splash_Frame, " ");
    
  } else {
    
    Nora_Boot();
        
    // Nora Sign:
    
    textAlign(LEFT);
    
    Absolute_Text_Size = (float(height) / float(displayHeight)) * 100;
      
    textSize(int(Absolute_Text_Size));
    
    fill(255, 255, 255, 255 - Boot_Fade * 2);
  
    text("NORA", 20, (float(height) / float(displayHeight)) * 110);
    
    
    // Response Query:
      
    textSize(int(Absolute_Text_Size * .55)); 
    
    fill(255,60,180,Output_Alpha);

    textLeading(25);
    
    textAlign(CENTER, CENTER);
    
    text(Finished_Output, 20, (float(height) / float(displayHeight)) * 200, width * .8746, height * .625);

    
    // Initialization Frame 1:

    if (Initialize_Frame == 1) {
      
      surface.setTitle("Nora, Your Virtual Companion.");
  
      surface.setResizable(false);

      surface.setLocation(int(displayWidth * .825), int(displayHeight * .56));
      
      surface.setAlwaysOnTop(true);      
      
    }
    
  }
  
}

After some more digging, turns out the problem is caused by a simple “Null Pointer Exception”, the VM error was clearly due to an internal mix-up, caused by such an error at runtime, apparently using int[ ] does not form a table after all…

I created a separate sketch to test my theory and I’m getting the same error, here’s my new code

IntList CurrentTime;

void draw() {
  
  CurrentTime.append(hour());
  
  print(CurrentTime);
  
}
final IntList currentTime = new IntList();

void setup() {
  currentTime.append(hour());
  println(currentTime);
  exit();
}

You’ve skipped creating an IntList via operator new:

In Java merely declaring a non-primitive variable like this IntList currentTime; doesn’t automatically creates an object for it.

All declared non-primitive variables got a default value null if we skip initializing it:
Why do I get a NullPointerException?

Thanks, I’m still pretty new to java and processing so… :+1: Now I can continue my project. Also thanks for the helpful link and code, I’ll be able to keep this in mind for the future. :grinning:

1 Like