Well I have a fix for the GDropList and I also noticed that the expanded list always starts with the first element even if it means the currently selected item is not visible in the drop list. I also have a fix for that and both will be in the next release.
the fact is sometimes my app works perfectly well, and sometimes, all the buttons in the GWindows are gone with a:...
These are difficult ones to solve but there are some hints in the error message.
Hint 1:
The exception is not occuring inside a G4P event handler because the error message would be very different e.g.
- ################ EXCEPTION IN EVENT HANDLER ################
- An error occured during execution of the eventhandler:
- CLASS: sketch_130426b METHOD: win_draw1
- Caused by java.lang.NullPointerException
- sketch_130426b.win_draw1(sketch_130426b.java:68)
- sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
- sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
- java.lang.reflect.Method.invoke(Method.java:597)
- g4p_controls.GWinApplet.draw(Unknown Source)
- processing.core.PApplet.handleDraw(PApplet.java:2266)
- processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
- processing.core.PApplet.run(PApplet.java:2140)
- java.lang.Thread.run(Thread.java:662)
- ##############################################################
Hint 2
If the error was caused by something inside the draw method then there would be an extra line in the exception message, see line 2 below e.g.
- Exception in thread "Animation Thread" java.lang.NullPointerException
- at sketch_130426b.draw(sketch_130426b.java:37)
- at processing.core.PApplet.handleDraw(PApplet.java:2266)
- at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
- at processing.core.PApplet.run(PApplet.java:2140)
- at java.lang.Thread.run(Thread.java:662)
Since this line is missing it means that the exception is being caused before the draw() method is executed so you should look at your setup() code.
If it's not too longe perhaps you could post you setup() code here.
I have had a look at the source code for PApplet and lines 2296-7 are
Graphics screen = getGraphics();
screen.drawImage(g.image, 0, 0, width, height, null);
The exception is thrown by the second line which means either
screen or
g is
null.
It seems to me that the most likely cause is that Processing is attempting to draw the screen before the graphics context is fully initialised.
So a couple of things you should do
- Make sure that the FIRST line in setup() is the call to size()
- All G4P controls are created in setup() AFTER the call to size()
So to create a secondary window with a button then it would look like this
- import g4p_controls.*;
- GWindow window1;
- GButton button1;
- public void setup(){
- size(480, 320, JAVA2D);
- window1 = new GWindow(this, "Window title", 0, 0, 240, 120, false, JAVA2D);
- window1.addDrawHandler(this, "win_draw1");
- button1 = new GButton(window1.papplet, 20, 7, 80, 30);
- button1.setText("Face text");
- button1.addEventHandler(this, "button1_click1");
- }
- public void draw(){
- background(230);
- }
- public void button1_click1(GButton source, GEvent event) {
- println("button1 - GButton event occured " + System.currentTimeMillis()%10000000 );
- }
- synchronized public void win_draw1(GWinApplet appc, GWinData data) {
- appc.background(230);
- }
HTH and BTW
If you want to set the frame title text but want the sketch to work safely as both application and applet then do this
if(frame != null)
frame.setTitle("My Title Text");
frame will be null when run as an applet so this will prevent the NullPointerException error you got before