So, I’m getting a null-pointer while trying to draw a TextField using LibGDX… and I can’t for the life of me figure out why.
public void draw(SpriteBatch batch, float x, float y, float width, float height)
{
batch.draw(chatboxTexture, x, y, width, height);
try
{
userInput.draw(batch, 1.0f);
}
catch(NullPointerException npe)
{
npe.printStackTrace();
}
}
The strange part is, that the TextField still draws, but it’s not usable (Can’t input text on it, etc)
Here’s the ChatBox constructor, which sets chatBoxTexture aswell
public Chatbox(Texture texture, int width, int height)
{
this.chatboxTexture = texture;
this.width = width;
this.height = height;
this.isInputActive = false;
this.message = "";
this.font = new BitmapFont();
this.textFieldStyle = new TextFieldStyle();
this.skin = new Skin();
this.textureAtlas = new TextureAtlas(Constants.CACHE_DIRECTORY + "/data/gui/packed/Interfaces.pack");
this.skin.addRegions(textureAtlas);
this.textFieldStyle.background = skin.getDrawable("chat_input");
this.textFieldStyle.font = font;
this.userInput = new TextField("Test", textFieldStyle);
this.userInput.setTextFieldListener(new TextFieldListener()
{
@Override
public void keyTyped(TextField textField, char key)
{
System.out.println("[Debug] Key Pressed: " + key);
}
});
this.userInput.setMessageText("Test");
}
So, the chatbox, and the text-field is drawn, however. It’s throwing nulls out the wazoo and I can’t figure out why.