Empty ByteBuffer size? WTF?
I made a custom-made text box for inputs, which works like entering text into a forum field. I can backspace, delete, type, etc... However, there's an issue when I call .setText(String) of my custom-made text field, and try to "delete" any of the letters already there. For the one field, I put "username" for obvious reasons.
If I type in a letter before erasing, it works fine, but if I erase what characters "exist", or rather, the ones that aren't empty spaces, then it crashes.
Anywho, down the line, this code gives me the following error from my LetterList class:
letterTex = TextureLoader.getTexture("PNG",letterFile,true);
(letterTex is a Texture object)
Exception in thread "main" java.lang.IllegalArgumentException: Buffer size <= 0
at java.io.BufferedInputStream.<init>(BufferedInputSt ream.java:193)
at org.newdawn.slick.opengl.CompositeImageData.loadIm age(CompositeImageData.java:53)
at org.newdawn.slick.opengl.CompositeImageData.loadIm age(CompositeImageData.java:43)
at org.newdawn.slick.opengl.InternalTextureLoader.get Texture(InternalTextureLoader.java:277)
at org.newdawn.slick.opengl.InternalTextureLoader.get Texture(InternalTextureLoader.java:231)
at org.newdawn.slick.opengl.InternalTextureLoader.get Texture(InternalTextureLoader.java:184)
at org.newdawn.slick.opengl.TextureLoader.getTexture( TextureLoader.java:64)
at org.newdawn.slick.opengl.TextureLoader.getTexture( TextureLoader.java:37)
at LetterList.letterSearch(LetterList.java:285)
at GameInputBox.drawTypedWord(GameInputBox.java:472)
at GameInputBox.draw(GameInputBox.java:226)
at IntroWindow.<init>(IntroWindow.java:221)
at MainControl.setMainState(MainControl.java:40)
at ConnectionTester.<init>(ConnectionTester.java:107)
at MainControl.setMainState(MainControl.java:31)
at MainControl.<init>(MainControl.java:13)
at MainControl.main(MainControl.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main (AppMain.java:120)
I've been digging and digging, and nothing seems off about my code. So I don't get it.
Here's the setText(String) method if it helps any:
Code java:
public void setText(String text) {
if (text.length() > maxLetters) {
try {
throw new TextLengthException(maxLetters);
} catch (TextLengthException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
System.exit(-1);
} // try - catch TextLengthException
} else if (text.length() < maxLetters) {
// save entry size
entryLength = text.length();
// create extra letters
addExtras = new char[maxLetters-text.length()-1];
// append letters to text
for (int i = 0; i < addExtras.length; ++i) {
addExtras[i] = '¶';
} // for loop
// add to text
text = text + String.valueOf(addExtras);
} // else - if
else
entryLength = text.length();
// finally save to array
saveEntry = text.toCharArray();
storeText(); // stores the created text to showText for visual display
} // setText(String)
EDIT: Apparently this bug happens when I run the program on my desktop Windows 7 Home Premium x86 (64-bit) OS, but when I run it on my laptop (has XP and 7 on 2 partitions), it works perfectly normal.
This was originally programmed on my laptop, so I never noticed the issue until recently when testing 2 programs on the Desktop.
Re: Empty ByteBuffer size?
I fixed this issue by loading the textures in an Array and assigning it later instead of creating a new Texture through TextureLoader every time. No issues loading it in the array, but for some reason glitches when I load it every time I erase a letter that was previously created.
I had a boolean in place to prevent it from re-loading the texture every loop until I "type" a letter in, although I can type a letter in the origional slot for whatever reason, I can't backspace or delete a letter previously created through setText(String); (my own custom setText() method for my class).
It works smoothly now. I think I was going to fix it anyway at one point, but I figured "why bother" because it worked fine on my laptop, but not on my desktop with the latest version of Windows 7 Home Premium OS.