SOLVED: GBUI TextField in StandardGame

I'm having difficulty creating a text input field so a player can enter his name. I am using the jme-bui11.jar. I keep getting a null pointer exception.



Exception in thread "main" java.lang.NullPointerException
   at java.io.Reader.<init>(Unknown Source)
   at java.io.InputStreamReader.<init>(Unknown Source)
   at com.jmex.bui.bss.BStyleSheetUtil.readFile(BStyleSheetUtil.java:67)
   at com.jmex.bui.bss.BStyleSheetUtil.readFile(BStyleSheetUtil.java:60)
   at com.jmex.bui.bss.BStyleSheetUtil.loadMultipleBSS(BStyleSheetUtil.java:197)
   at com.jmex.bui.bss.BStyleSheetUtil.getStyleSheet(BStyleSheetUtil.java:125)
   at com.jmex.bui.BuiSystem.init(BuiSystem.java:98)
   at com.fox.eldertale.client.states.LoginState.<init>(LoginState.java:36)
   at com.fox.eldertale.client.ElderTaleClient.<init>(ElderTaleClient.java:18)
   at com.fox.eldertale.client.ElderTaleClient.main(ElderTaleClient.java:50)



My LoginGameState looks like this:


package com.fox.eldertale.client.states;

import java.util.concurrent.Callable;

import com.jme.bounding.BoundingBox;
import com.jme.input.InputHandler;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.state.LightState;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.Timer;
import com.jmex.bui.BComboBox;
import com.jmex.bui.BDecoratedWindow;
import com.jmex.bui.BTextField;
import com.jmex.bui.BWindow;
import com.jmex.bui.BuiSystem;
import com.jmex.bui.PolledRootNode;
import com.jmex.bui.layout.GroupLayout;
import com.jmex.game.state.BasicGameState;

public class LoginState extends BasicGameState {
   private InputHandler input;
   
   public LoginState(String name) {
      super(name);
      
       createInput();
      
       BuiSystem.init("/assets/styles/menubase.bss");
       getRootNode().attachChild(BuiSystem.getRootNode());
      
       GameTaskQueueManager.getManager().update(new Callable() {
           public Object call() {
               createWindows();
               return null;
           }
       });
   }
   
   private InputHandler createInput() {
      input = new InputHandler();
      return input;
   }
   
   public void createWindows() {
      BWindow window = new BWindow(BuiSystem.getStyle(), GroupLayout.makeVStretch());

        BTextField playerTxt = new BTextField("Enter player name...");

        window.add(playerTxt);
        window.setSize(100, 25);

        BuiSystem.addWindow(window);
        window.center();

   }
}



This seems like the correct way to display a text field using StandardGame. I based this on a previous post about GBUI and StandardGame.

Has anyone else encountered this problem and found a solution or is someone using GBUI in StandardGame successfully and care to share?

I'd appreciate any help or advice.

Thanks!

from the exception it looks like it couldn't find your resource file (the bss).



Is the bss in your classpath?

… Yeah it does seem like that  :oops:



Thanks for pointing that out. I've added the bss file to the class path and get passed that error but now I receive this error:



WARNING: Child operation choked[op=com.jmex.bui.BContainer$2@1b06041, child=com.jmex.bui.BTextField@7f5580].
java.lang.NullPointerException
   at com.jmex.bui.BTextField.recreateGlyphs(BTextField.java:383)
   at com.jmex.bui.BTextField.wasAdded(BTextField.java:280)
   at com.jmex.bui.BContainer$2.apply(BContainer.java:323)
   at com.jmex.bui.BContainer.applyOperation(BContainer.java:393)
   at com.jmex.bui.BContainer.wasAdded(BContainer.java:321)
   at com.jmex.bui.BWindow.setRootNode(BWindow.java:228)
   at com.jmex.bui.BRootNode.addWindow(BRootNode.java:105)
   at com.jmex.bui.BRootNode.addWindow(BRootNode.java:65)
   at com.jmex.bui.BuiSystem.addWindow(BuiSystem.java:226)
   at com.fox.eldertale.client.states.LoginState.createWindows(LoginState.java:60)
   at com.fox.eldertale.client.states.LoginState$1.call(LoginState.java:41)
   at com.jme.util.GameTask.invoke(GameTask.java:101)
   at com.jme.util.GameTaskQueue.execute(GameTaskQueue.java:115)
   at com.jmex.game.StandardGame.update(StandardGame.java:320)
   at com.jmex.game.StandardGame.run(StandardGame.java:198)
   at java.lang.Thread.run(Unknown Source)
Exception in thread "main" java.lang.NullPointerException
   at com.fox.eldertale.client.ElderTaleClient.<init>(ElderTaleClient.java:43)
   at com.fox.eldertale.client.ElderTaleClient.main(ElderTaleClient.java:50)
May 12, 2008 10:00:53 PM class com.jme.util.GameTask invoke()
SEVERE: Exception
java.lang.NullPointerException
   at com.jmex.bui.BTextField.computePreferredSize(BTextField.java:346)
   at com.jmex.bui.BComponent.getPreferredSize(BComponent.java:178)
   at com.jmex.bui.layout.GroupLayout.computeChildDimens(GroupLayout.java:325)
   at com.jmex.bui.layout.GroupLayout.computeDimens(GroupLayout.java:302)
   at com.jmex.bui.layout.VGroupLayout.layoutContainer(VGroupLayout.java:80)
   at com.jmex.bui.BContainer.layout(BContainer.java:290)
   at com.jmex.bui.BContainer.validate(BContainer.java:268)
   at com.jmex.bui.BWindow.setRootNode(BWindow.java:232)
   at com.jmex.bui.BRootNode.addWindow(BRootNode.java:105)
   at com.jmex.bui.BRootNode.addWindow(BRootNode.java:65)
   at com.jmex.bui.BuiSystem.addWindow(BuiSystem.java:226)
   at com.fox.eldertale.client.states.LoginState.createWindows(LoginState.java:60)
   at com.fox.eldertale.client.states.LoginState$1.call(LoginState.java:41)
   at com.jme.util.GameTask.invoke(GameTask.java:101)
   at com.jme.util.GameTaskQueue.execute(GameTaskQueue.java:115)
   at com.jmex.game.StandardGame.update(StandardGame.java:320)
   at com.jmex.game.StandardGame.run(StandardGame.java:198)
   at java.lang.Thread.run(Unknown Source)



Does this error imply something wrong with the bss file? I am using the same ones in the svn rsrc folder until I get more familiar with the library.

I've found that either removing BTextField or instantiating it without a string causes no error to occur but nothing is displayed either.

BTextField should allow the String to be in the constructor.  I don't know why it will not let the constructor complete in that manner.



the fix is simply to add the text after the initialization.  I'll add this to the issues portion of the google site


BTextField playerTxt = new BTextField();
playerTxt.setText("Enter player name... ");
window.add(playerTxt);

Actually I've found that I can't instantiate any of the controls except BWindow which I can get to show up now, I am getting a NoSuchMethodError on BImage. Perhaps I am using GBUI incorrectly. Do you happen to have a really basic StandardGame example for GBUI? Something that just displays a text field or button?

Interesting.  I'll put together a simple example of using StandardGame… The code I do have is from my game and is a little more complicated.



Can you email me the code you're working with?  Maybe I can see what the code is doing.



thx



timo

I've reviewed this (and replied to mr todd)… the issue is that the call for GBUI windows didn't happen inside of the GameTaskQueueManager calls

I'm adding a new "test" example to the core code and will check that in later today.



GameTaskQueueManager.getManager().update(new Callable<Object>() {
    public Object call() throws Exception {
        createWindows();
        return null;
    }
});



thx

timo

Also, I was using an older GBUI jar that was not working well with the JME version my project was using. After the advice I was getting no such method errors when GBUI was making calls on the JME library. The solution to that problem was to build the latest GBUI from SVN.



Thanks again Gerbildrop.

I'm still having a lot of trouble with this. I built the latest version from the svn repository.



I make sure to call everything in the OpenGL thread, but once I try to add any sort of text, - either the text doesn't display at all, or I get the following stack trace:


Jun 13, 2008 2:57:36 PM com.jmex.game.DefaultUncaughtExceptionHandler uncaughtException
SEVERE: Main game loop broken by uncaught exception
org.lwjgl.opengl.OpenGLException: Invalid value (1281)
   at org.lwjgl.opengl.Util.checkGLError(Util.java:50)
   at org.lwjgl.opengl.Display.swapBuffers(Display.java:606)
   at org.lwjgl.opengl.Display.update(Display.java:625)
   at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(Unknown Source)
   at com.jmex.game.StandardGame.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)



Help would be appreciated, BUI looks promising and well documented. I'm using an Intel integrated graphics chip, which I've heard has some trouble with some OpenGL calls...and I've also heard OpenGLException 1281 to be caused by textures which aren't 2^n in dimensions.

I thought I had replied to this.  Can you pm me and I'll send you my email and if you could then send me the code and I'll see what's going on with it.



thx



timo