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 23 of 23

Thread: Random Errors Occurring When Running Game in Eclipse

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random Errors Occurring When Running Game in Eclipse

    Greetings.

    In order to improve my programming skills I am following Notch (Minecraft creator) creating a game he made over this past weekend called Prelude of the Chambered (called Escape during coding stages). I've been going well and getting the same results as he has but all of a sudden I am getting unexpected, random errors which Notch wasn't getting. This is stopping me from running the game.

    I am getting no errors in my code, but when I press the mighty green run button, the following errors are appearing in the console.

    Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: -6
    	at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
    	at com.mojang.escape.gui.Screen.render(Screen.java:34)
    	at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
    	at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
    	at java.lang.Thread.run(Unknown Source)

    I have no idea why they are appearing, and how to fix them.

    Help would be greatly appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Have you looked at the lines in your code where the array index goes out of bounds and determined why it gets a bad value? What code is at line 34 in Screen.java? Or line 105 in EscapeComponent.java

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    If you have no idea where these errors are coming from, I really really encourage you to start out with something smaller.

    The competition Notch wrote that game for was called Ludum Dare, and there were almost 600 other entrants- many of which were written in Java, and all of which were open source. I suggest you start with the basic tutorials first, then when you're comfortable with the basics, start playing with a more basic game from the competition. You don't get to be on Notch's level overnight, or just by playing with somebody else's code.

    JavaPF- This makes at least three! :p :p :p
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    Have you looked at the lines in your code where the array index goes out of bounds and determined why it gets a bad value? What code is at line 34 in Screen.java? Or line 105 in EscapeComponent.java
    I've had these parts of the code in there for a while, I'd run it and it would work, but all of a sudden these errors are popping up which is what I find so strange about it.

    at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
    pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];

    at com.mojang.escape.gui.Screen.render(Screen.java:34)
    viewport.render(game);

    at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
    screen.render(game);

    at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
    render();

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    pixels[x + y * width] = ...
    What are the values of x, y and width when this statement is executed?
    Could the value of the expression be -6?

  6. #6
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    What are the values of x, y and width when this statement is executed?
    Could the value of the expression be -6?
    This is the whole section.

    			for (int x=0; x<width; x++) {
    				double xd = (x-width/2.0)/height;
    				xd *= z;
    				int xx = (int) (xd + game.time*0.1)%7;
    				int yy = (int) (z + game.time*0.1)%7;
     
    				zBuffer[x+y*width] = z;
    				pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];
    			}

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Add a println just before the statement with the invalid index to print out the contents of all the variables used in the computing the index.

  8. #8
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    Add a println just before the statement with the invalid index to print out the contents of all the variables used in the computing the index.
    That only causes more errors, unless I am stupid and I;m doing it wrong.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    That only causes more errors, unless I am stupid and I;m doing it wrong.
    I don't see how a println statement can cause errors.
    Please copy and paste here the full text of the error messages.

  10. #10
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    I don't see how a println statement can cause errors.
    Please copy and paste here the full text of the error messages.
    I've posted all the errors on the first post and here is the specific version of each error and what line it is.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    That error message was BEFORE you added the println. What about AFTER you added the println?
    Where are the print outs of the values used in the line where the index value is wrong?

    Did you add a println statement to the code to show the variables values?
    What did it print out?

  12. #12
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    That error message was BEFORE you added the println. What about AFTER you added the println?
    Where are the print outs of the values used in the line where the index value is wrong?

    Did you add a println statement to the code to show the variables values?
    What did it print out?
    I put printIn on one of the lines.

    CODE LINE Before:
    pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];

    CODE LINE After:
    printIn pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];

    ERRORS Before:
    Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: -5
    	at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
    	at com.mojang.escape.gui.Screen.render(Screen.java:34)
    	at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
    	at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
    	at java.lang.Thread.run(Unknown Source)

    ERRORS After:
    	println cannot be resolved to a variable
     
    	at com.mojang.escape.gui.Bitmap3D.render(Bitmap3D.java:33)
    	at com.mojang.escape.gui.Screen.render(Screen.java:34)
    	at com.mojang.escape.EscapeComponent.render(EscapeComponent.java:105)
    	at com.mojang.escape.EscapeComponent.run(EscapeComponent.java:92)
    	at java.lang.Thread.run(Unknown Source)

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    println refers to the println method of the out variable in the System class.
    You use it like this:
    System.out.println("var=" + var); // print the value of var

    You need to print out the values of the variables used to compute the index.

  14. #14
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    println refers to the println method of the out variable in the System class.
    You use it like this:
    System.out.println("var=" + var); // print the value of var

    You need to print out the values of the variables used to compute the index.
    System.out.println("var=" + var); // pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];

    Like so?

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    No. Comments do not cause anything to print out.
    Do you know what a variable is?
    Do you know what variables are being used to compute the indexes to the arrays?
    Those are what you should print out. Show the variables values.

  16. #16
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    No. Comments do not cause anything to print out.
    Do you know what a variable is?
    Do you know what variables are being used to compute the indexes to the arrays?
    Those are what you should print out. Show the variables values.
    Urgh. Silly me. I see now. I will do now.

  17. #17
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    I understand what you are meaning for me to do, but I don't know how to put that in the code, from what I've tried I haven't been successful.

    Would it be like, if my code was this?

    pixels[x + y * width] = Art.floors.pixels[xx + yy * 64];

    I'd make it this?

    System.out.println(pixels[x + y * width] = Art.floors.pixels[xx + yy * 64]);

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Do you know what a variable is?
    Do you know what variables are being used to compute the indexes to the arrays?
    Those are what you should print out. Show the variables' values.
    The variables you should print out the values of are: x, y, width, xx and yy.
    They are used to compute the indexes to the two arrays.
    The index to an array is what is between the []s

    What happened when you executed this statement?
    System.out.println(pixels[x + y * width] = Art.floors.pixels[xx + yy * 64]);

  19. #19
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    Do you know what a variable is?
    Do you know what variables are being used to compute the indexes to the arrays?
    Those are what you should print out. Show the variables' values.
    The variables you should print out the values of are: x, y, width, xx and yy.
    They are used to compute the indexes to the two arrays.
    The index to an array is what is between the []s

    What happened when you executed this statement?
    System.out.println(pixels[x + y * width] = Art.floors.pixels[xx + yy * 64]);
    Instead I did,

    System.out.println(x + y + " error");

    A whole lost of random number errors came out, here are only a few from the huge list.
    168 error
    169 error
    170 error
    171 error
    172 error
    173 error
    174 error
    175 error
    176 error
    177 error

  20. #20
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Is there a reason you've been refusing to answer the questions you've been asked? Norm, you deserve a medal for your patience- but I'm not that patient.

    Step through your program with a debugger, or add simple print statements like Norm suggested. Why are you using an assignment statement inside a print line?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    System.out.println(x + y + " error");
    The problem with the way this prints out is that you do NOT see the values of x and y. You see the sum of the variables.
    Try this: System.out.println("x=" + x + ", y" + y);

    What was the last values that printed out before you got the error:
    ArrayIndexOutOfBoundsException: -5

    Those last values are the ONLY values you are interested in. The others are not what you need to see.

  22. #22
    Junior Member
    Join Date
    Aug 2011
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    Quote Originally Posted by Norm View Post
    The problem with the way this prints out is that you do NOT see the values of x and y. You see the sum of the variables.
    Try this: System.out.println("x=" + x + ", y" + y);

    What was the last values that printed out before you got the error:
    ArrayIndexOutOfBoundsException: -5

    Those last values are the ONLY values you are interested in. The others are not what you need to see.
    Using that, I got, once again a long list, here are some....
    x=0, y0
    x=1, y0
    x=2, y0
    x=3, y0
    x=4, y0
    x=5, y0
    x=6, y0
    x=7, y0

    x=153, y13
    x=154, y13
    x=155, y13
    x=156, y13
    x=157, y13
    x=158, y13
    x=159, y13
    Last edited by WhenThCome4Me; September 1st, 2011 at 02:47 AM.

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Random Errors Occurring When Running Game in Eclipse

    What were the last values that printed out before you got the error:
    ArrayIndexOutOfBoundsException: -5

    Are you getting the error still?

Similar Threads

  1. Generation of random number using random class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 7th, 2011, 05:46 PM
  2. Reverse Random Number Game
    By koryvandell in forum Java Theory & Questions
    Replies: 2
    Last Post: April 4th, 2011, 01:11 AM
  3. Replies: 3
    Last Post: February 23rd, 2011, 01:27 AM
  4. Replies: 3
    Last Post: October 8th, 2010, 09:21 AM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 06:10 AM