Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Empty ByteBuffer size?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    11
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Exclamation 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:
    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.
    Last edited by squeakbox; September 12th, 2012 at 12:10 PM.


  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    11
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default 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.

Similar Threads

  1. Empty If Statement
    By lightOfDay in forum Loops & Control Statements
    Replies: 5
    Last Post: June 14th, 2012, 08:41 AM
  2. Check if 'int' is empty
    By TrYk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 10th, 2012, 08:34 AM
  3. How to not accept empty jfield?
    By myexternall11 in forum Java Theory & Questions
    Replies: 1
    Last Post: February 20th, 2012, 04:38 AM
  4. Limit File Size or Request Size
    By tarek.mostafa in forum Java Servlet
    Replies: 3
    Last Post: June 12th, 2010, 04:28 PM
  5. Limit File Size or Request Size
    By tarek.mostafa in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: June 11th, 2010, 07:21 AM