Getting a "Target VM failed to initialize" and "NullPointerException" error - Arduino to Processing

edited March 2017 in Programming Questions

I am connecting between an Arduino and Processing, and it runs fine for a few seconds, but as soon as Arduino sends "null" I recieve the "NullPointerException" and the "Target VM failed to initialize" error simultaneously. This doesn't happen when the text only prints to the console, and doesn't go into the "run" screen. "Target VM..." seemed to happen to lots of people using nVidia graphics, I have Integrated (intel I believe) so I don't think that is the issue

I also get a "No glyph found for the (\u000D) character" when it prints the first info from Arduino, but it seems to pass that pretty quickly, and I am not seeing an issue from that, so not too worried.

It's not a "serial handshake", so I would think it would be simple, but I am having trouble finding the issue.

Processing Code:

import processing.serial.*;

PFont f;

Serial myPort;  // Create object from Serial class
String val = "";     // Data received from the serial port

void setup() {

  size(1000,1000);

  f = loadFont("CenturyGothic-Bold-48.vlw");

  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

}

void draw() {

  background(255);

  if ( myPort.available() > 0) {
  val = myPort.readStringUntil('\n');
  }

  println(val); //Prints data to console

  textFont(f,16);  //When this line and the 3 beneath it are not here, it runs fine
  fill(0);
  textAlign(CENTER);
  text(val,width/2,500); //Prints data to 'Run' screen

}

Arduino Code:\

#include "HX711.h"

#define calibration_factor -11860.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define DOUT  3
#define CLK  2

int lossValue;

HX711 scale(DOUT, CLK);

void setup() {
  Serial.begin(9600);

  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

}

void loop() {
  lossValue = abs(scale.get_units()) * .05;

  Serial.print("Loss: ");
  Serial.print(abs(lossValue), 3);
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor  Serial.println();
  Serial.println();

  delay(500);

}

Answers

  • Could I make 'null' worth something, so instead of receiving null, it would display "testing" or "0"?

  • Answer ✓

    Would adding this: if(val==null) return; in line 26 solve your problem?

    Kf

  • That did it! Thanks!

Sign In or Register to comment.