Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

g4p NullPointerException on event handler

$
0
0

I'm trying to set a default max and min range of a value that can be in a textfield if user enters val > 350, then setText to 350,..etc

getting:

java.lang.NullPointerException at g4p_controls.GTextField.keyEvent(Unknown Source) at g4p_controls.GWindowImpl.keyEvent(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1427) at processing.core.PApplet.handleMethods(PApplet.java:1622) at processing.core.PApplet.handleKeyEvent(PApplet.java:2957) at processing.core.PApplet.dequeueEvents(PApplet.java:2610) at processing.core.PApplet.handleDraw(PApplet.java:2448) at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1557) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)

code:

int TEMP_MAX = 350; int TEMP_MIN = 100;

public void textfield1_change1(GTextField source, GEvent event) { println("textfield1 - GTextField >> GEvent." + event + " @ " + millis()); if (event == GEvent.CHANGED) { int tempValue = int(textfield1.getText()); //convert string to int if (tempValue < 0) source.setText(str(TEMP_MIN)); else if (tempValue > TEMP_MAX) source.setText(str(TEMP_MAX)); } }

public void createGUI(){ G4P.messagesEnabled(false); G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME); G4P.setCursor(ARROW); surface.setTitle("Sketch Window"); textfield1 = new GTextField(this, 121, 63, 160, 30, G4P.SCROLLBARS_NONE); textfield1.setOpaque(true); textfield1.addEventHandler(this, "textfield1_change1"); }

GTextField textfield1;


Viewing all articles
Browse latest Browse all 2896

Trending Articles