gBUI -- NullPointerException on BScrollingList.removeValues()

first of all, let me thank all the gBUI coders – after many headaches from fenggui etc i finally have a gui for my game.



i'm happy :slight_smile:



but i have a question… i have a BScrollingList<String, BButton>, which i initialize using the standard code from the tutorial:


        roster = new BScrollingList<String, BButton>() {
            @Override
            public BButton createComponent(String str) {
                BButton b    = new BButton(str, listener, str);
                b.setStyleClass("buttonlobbyroster");       
                return b;
            }
        };
       add(roster);
   
       for (int i = 0; i < 2; i++)
           roster.addValue("Player #" + i, false);



but later, i call roster.removeValues() and i get this exception. i tried removeAll and i get a similar exception (by the way, what's the difference between removeAll and removeValues??)

java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glDeleteTextures(GL11.java:716)
at com.jme.scene.state.lwjgl.LWJGLTextureState.deleteAll(LWJGLTextureState.java:2112)
at com.jme.scene.state.lwjgl.LWJGLTextureState.deleteAll(LWJGLTextureState.java:2074)
at com.jmex.bui.BImage$1.releaseTextures(BImage.java:391)
at com.jmex.bui.BImage.releaseTexture(BImage.java:366)
at com.jmex.bui.BImage.release(BImage.java:342)
at com.jmex.bui.text.AWTTextFactory$1.wasRemoved(AWTTextFactory.java:340)
at com.jmex.bui.Label$Text.wasRemoved(Label.java:654)
at com.jmex.bui.Label.wasRemoved(Label.java:174)
at com.jmex.bui.BLabel.wasRemoved(BLabel.java:168)
at com.jmex.bui.BContainer.remove(BContainer.java:172)
at com.jmex.bui.BContainer.removeAll(BContainer.java:206)
at com.jmex.bui.BScrollingList.removeValues(BScrollingList.java:82)

any suggestions? my goal is to simply refresh the list with new values. so any alternate way to do that would also work.

it also might be related to this thread http://www.jmonkeyengine.com/jmeforum/index.php?topic=9908.0

(fyi i'm using jme2 and the google code svn/trunk version of gBUI that's probably less than a week or two old)
l---l said:

first of all, let me thank all the gBUI coders -- after many headaches from fenggui etc i finally have a gui for my game.


I'd be interested in what headaches you had so I can keep track.  I'm sure the fenggui guys would be interested in what you preferred as well :)

l---l said:

i'm happy :)


Good:)

l---l said:

but i have a question... i have a BScrollingList<String, BButton>, which i initialize using the standard code from the tutorial:

        roster = new BScrollingList<String, BButton>() {
            @Override
            public BButton createComponent(String str) {
                BButton b    = new BButton(str, listener, str);
                b.setStyleClass("buttonlobbyroster");       
                return b;
            }
        };
       add(roster);
   
       for (int i = 0; i < 2; i++)
           roster.addValue("Player #" + i, false);



but later, i call roster.removeValues() and i get this exception. i tried removeAll and i get a similar exception (by the way, what's the difference between removeAll and removeValues??)

java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glDeleteTextures(GL11.java:716)
at com.jme.scene.state.lwjgl.LWJGLTextureState.deleteAll(LWJGLTextureState.java:2112)
at com.jme.scene.state.lwjgl.LWJGLTextureState.deleteAll(LWJGLTextureState.java:2074)
at com.jmex.bui.BImage$1.releaseTextures(BImage.java:391)
at com.jmex.bui.BImage.releaseTexture(BImage.java:366)
at com.jmex.bui.BImage.release(BImage.java:342)
at com.jmex.bui.text.AWTTextFactory$1.wasRemoved(AWTTextFactory.java:340)
at com.jmex.bui.Label$Text.wasRemoved(Label.java:654)
at com.jmex.bui.Label.wasRemoved(Label.java:174)
at com.jmex.bui.BLabel.wasRemoved(BLabel.java:168)
at com.jmex.bui.BContainer.remove(BContainer.java:172)
at com.jmex.bui.BContainer.removeAll(BContainer.java:206)
at com.jmex.bui.BScrollingList.removeValues(BScrollingList.java:82)


Interesting!  Suffer... j/k let me pull that up right now and debug it for you.  I don't believe the tests, nor the tutorial cover the removeAll nor the removeValues portions.  I'll get you a complete answer on the differences after I debug what's going on.

l---l said:

any suggestions? my goal is to simply refresh the list with new values. so any alternate way to do that would also work.

it also might be related to this thread http://www.jmonkeyengine.com/jmeforum/index.php?topic=9908.0


I think I found an answer to the thread from above, but I'll have to check my emails.  I think there was a workaround, but I don't remember, I need to update that thread as well.

l---l said:

(fyi i'm using jme2 and the google code svn/trunk version of gBUI that's probably less than a week or two old)

The removeValues is what you were looking for.  It will clear all of the values and basically all children on the scrolling list, "resetting," if you will, the display so there's a panel, the list, scrollbar and nothing else.



removeAll is an artifact of BComponent and will remove everything.



The easiest way to test these two things to see exactly what they do (without going through the code like I did,) is to take the ScrollingListTest and on line 63-ish add list.removeAll() or list.removeValues() then compile and run.  For more "realism" you can add a listener and a button to the window that when clicked will do the same thing.  I'll add this as a new test to the GBUI framework.



However, on to the rest of this reply.  Running either removeValues or removeAll did not cause any issues for me.



I do see that add(roster) is in your code… is the portion of the code, you've added the roster section, a BWindow?



I've not tried it yet, but this may be where an NPE would come up.  If you can, send me just the class that this roster is in and I'll run it and debug it and see what's going on, if I can replicate the NPE you're getting.



timo

standtrooper AT gmail DOT com

I've checked in several new classes for illustrating the differences between removeAll and removeValues.



ScrollingListTestWithButton is the main class – I'll have to clean up others

SLTWBActionListener is the set of code that pertains only to the ActionListener for this test

BButtonScrollingList is the impl class of the BScrollingList class specifically for BButtons



The only purpose of the last two external classes was simply for OOD and because the code isn't part of the example, where the real part of the example is in the BContainer that adds three buttons to test and the Window that adds the BButtonScrollingList and the BContainer with the three buttons.



I'm also adding another note to my notes that these examples need to be refactored out of the test directory and into their own example directory.



I also need to add more tests… ah but another day:)



timo