We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello!
I currently am working on a project using eclipse and have been getting a NullPointerException Error. I was able to mimic this in a small program with the stack provided below. The error in this example is coming from this.textSize = textWidth(name.charAt(0)); where the nullpointer is then saying it is coming from textWidth within PApplet. The stacktrace is provided below as well:
TestProjectFile:
package testproject;
import processing.core.PApplet;
import processing.core.PFont;
@SuppressWarnings("serial")
public class TestProject extends PApplet {
PFont p;
TestClass1 test;
public void setup() {
size(500, 500);
p = createFont("Times-Roman", 40);
textFont(p, 40);
testFunction();
}
public void draw() {
ellipse(100, 100, 100, 100);
}
public void testFunction(){
test = new TestClass1("testString");
}
}
TestClass1 File:
package testproject;
import processing.core.PApplet;
@SuppressWarnings("serial")
public class TestClass1 extends PApplet{
String name;
float textSize;
TestClass1(String name){
this.name = name;
this.textSize = textWidth(name.charAt(0));
}
}
and the stacktrace:
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PApplet.textWidth(PApplet.java:13097)
at testproject.TestClass1.<init>(TestClass1.java:13)
at testproject.TestProject.testFunction(TestProject.java:25)
at testproject.TestProject.setup(TestProject.java:17)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Unknown Source)
I found another person with a similar issue: http://forum.processing.org/one/topic/problems-with-textwidth.html But even setting textSize in setup still showed an error.
Any help would be greatly appreciated!
Thanks
Andrew S
Answers
Yup this is exactly what I needed! Getting some new errors now but looking more into them since they deal with running out of java heap space in eclipse. Thanks a bunch!