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: IndexOutOfBoundsException - HELP! DON’T KNOW EXACTLY WHAT THIS MEANS. :(

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy IndexOutOfBoundsException - HELP! DON’T KNOW EXACTLY WHAT THIS MEANS. :(

    keep getting this error, but it don’t appear from time to time, there are times that it don’t and there are times when this appears. I have a timer that is shown in the gui but I don’t use invokelater to show the timer to gui, all I do is that I use MTTextArea to make it appear in the gui. Well, I can’t point out the problem because it says there the arraylist is unknown source… I’m a beginner programmer and it’s the first time I encountered this kind of exception… please somebody explain to me what is going on? and why this exception keeps on appearing? And I don’t have an arraylist in my code by the way…


    here's the actual code that I believe where I'm getting the error: (it's not the full code though... because it is very long you might get headaches )


    public class TimeClass extends TimerTask {
    int counter;
    PImage imggo = mtApp.loadImage("Puzzle/datas/gameover.png");
    MTRectangle re = new MTRectangle(mtApp, 400, 200);
    PImage ta = mtApp.loadImage("Puzzle/datas/tryagain.png");
    final MTRectangle tryAgain = new MTRectangle(mtApp,
    (mtApp.width / 2) - 150, (mtApp.height / 2), 0, 300, 100);
    final MTTextArea yestry = new MTTextArea(mtApp, font);
    final MTTextArea noexit = new MTTextArea(mtApp, font);

    public TimeClass(int counter) {
    this.counter = counter;
    }

    private long TimeInSeconds = 0, TimeInMinutes = 0;

    @Override
    public void run() {

    try{
    TimeInSeconds++;
    if (TimeInSeconds < 10) {
    timercount.setText(" 0" + TimeInSeconds);
    } else {
    timercount.setText(" " + TimeInSeconds);
    }
    if (TimeInSeconds == 59) {

    TimeInSeconds = 0;
    TimeInMinutes++;
    timercount2.setText(TimeInMinutes + " : ");

    }

    if (TimeInMinutes == 60) {
    TimeInMinutes = 0;

    }
    }catch (IndexOutOfBoundsException ex){
    System.out.println(ex.getCause());
    }

    if (horizontalTiles == 3 && TimeInSeconds == 1) {
    timer.cancel();
    timer.purge();
    puzzleGroup.setVisible(false);
    for (MTComponent c : puzzleGroup.getChildren()) {
    c.destroy();
    }
    puzzleGroup.destroy();
    System.out.println("GameOver");

    System.out.println("RECORD: " + timercount.getText());
    re.setPositionGlobal(new Vector3D(mtApp.width / 2,
    mtApp.height / 2 - 150));
    re.setNoStroke(true);
    re.setTexture(imggo);
    re.setVisible(true);

    tryAgain.setPickable(false);
    tryAgain.setNoStroke(true);
    tryAgain.setTexture(ta);
    tryAgain.setVisible(true);

    yestry.setFillColor(new MTColor(0, 255, 255, 150));
    yestry.setStrokeColor(new MTColor(0, 255, 255, 200));
    yestry.setText("Yes");
    clearAllGestures(yestry);
    yestry.setVisible(true);
    getCanvas().addChild(yestry);
    yestry.setPositionGlobal(new Vector3D((mtApp.width / 2) - 100,
    (mtApp.height / 2) + 200, 0));
    yestry.registerInputProcessor(new TapProcessor(mtApp, 2000));

    yestry.addGestureListener(TapProcessor.class,
    new IGestureEventListener() {
    public boolean processGestureEvent(MTGestureEvent ge) {
    TapEvent th = (TapEvent) ge;

    switch (th.getId()) {
    case TapEvent.GESTURE_STARTED:
    break;
    case TapEvent.GESTURE_UPDATED:
    break;
    case TapEvent.GESTURE_ENDED:
    noexit.destroy();


    mtApp.pushScene();
    tryagain = new puzzlescene(mtApp,
    "The Brain Tickler");
    mtApp.addScene(tryagain);
    mtApp.changeScene(tryagain);

    System.out.println("stop now");
    break;
    default:
    break;
    }
    return false;
    }
    });

    noexit.setFillColor(new MTColor(0, 255, 255, 150));
    noexit.setStrokeColor(new MTColor(0, 255, 255, 200));
    noexit.setText("Exit");
    clearAllGestures(noexit);
    noexit.setVisible(true);
    getCanvas().addChild(noexit);
    noexit.setPositionGlobal(new Vector3D((mtApp.width / 2) + 100,
    (mtApp.height / 2) + 200, 0));
    noexit.registerInputProcessor(new TapProcessor(mtApp, 2000));

    noexit.addGestureListener(TapProcessor.class,
    new IGestureEventListener() {
    public boolean processGestureEvent(MTGestureEvent ge) {
    TapEvent th = (TapEvent) ge;

    switch (th.getId()) {
    case TapEvent.GESTURE_STARTED:
    break;
    case TapEvent.GESTURE_UPDATED:
    break;
    case TapEvent.GESTURE_ENDED:
    yestry.destroy();
    tryagain.destroy();
    record.destroy();
    System.exit(0);
    break;
    default:
    break;
    }
    return false;
    }
    });

    getCanvas().addChild(tryAgain);
    getCanvas().addChild(yestry);
    getCanvas().addChild(noexit);
    getCanvas().addChild(re);

    }
    if (horizontalTiles == 4 && TimeInSeconds == 4) {
    timer.cancel();
    timer.purge();
    puzzleGroup.setVisible(false);
    puzzleGroup.setVisible(false);
    for (MTComponent c : puzzleGroup.getChildren()) {
    c.destroy();
    }
    puzzleGroup.destroy();
    getscore(counter);
    System.out.println("Score: " + score);
    System.out.println("RECORD: " + timercount.getText());
    re.setPositionGlobal(new Vector3D(mtApp.width / 2,
    mtApp.height / 2 - 150));
    re.setNoStroke(true);
    re.setTexture(imggo);
    re.setVisible(true);

    tryAgain.setPickable(false);
    tryAgain.setNoStroke(true);
    tryAgain.setTexture(ta);
    tryAgain.setVisible(true);

    yestry.setFillColor(new MTColor(0, 255, 255, 150));
    yestry.setStrokeColor(new MTColor(0, 255, 255, 200));
    yestry.setText("Yes");
    clearAllGestures(yestry);
    yestry.setVisible(true);
    getCanvas().addChild(yestry);
    yestry.setPositionGlobal(new Vector3D((mtApp.width / 2) - 100,
    (mtApp.height / 2) + 200, 0));
    yestry.registerInputProcessor(new TapProcessor(mtApp, 2000));

    yestry.addGestureListener(TapProcessor.class,
    new IGestureEventListener() {
    public boolean processGestureEvent(MTGestureEvent ge) {
    TapEvent th = (TapEvent) ge;

    switch (th.getId()) {
    case TapEvent.GESTURE_STARTED:
    break;
    case TapEvent.GESTURE_UPDATED:
    break;
    case TapEvent.GESTURE_ENDED:
    noexit.destroy();

    mtApp.pushScene();
    tryagain = new puzzlescene(mtApp,
    "The Brain Tickler");
    mtApp.addScene(tryagain);
    mtApp.changeScene(tryagain);

    System.out.println("stop now");
    break;
    default:
    break;
    }
    return false;
    }
    });

    noexit.setFillColor(new MTColor(0, 255, 255, 150));
    noexit.setStrokeColor(new MTColor(0, 255, 255, 200));
    noexit.setText("Exit");
    clearAllGestures(noexit);
    noexit.setVisible(true);
    getCanvas().addChild(noexit);
    noexit.setPositionGlobal(new Vector3D((mtApp.width / 2) + 100,
    (mtApp.height / 2) + 200, 0));
    noexit.registerInputProcessor(new TapProcessor(mtApp, 2000));

    noexit.addGestureListener(TapProcessor.class,
    new IGestureEventListener() {
    public boolean processGestureEvent(MTGestureEvent ge) {
    TapEvent th = (TapEvent) ge;

    switch (th.getId()) {
    case TapEvent.GESTURE_STARTED:
    break;
    case TapEvent.GESTURE_UPDATED:
    break;
    case TapEvent.GESTURE_ENDED:
    yestry.destroy();
    tryagain.destroy();
    record.destroy();
    System.exit(0);
    break;
    default:
    break;
    }
    return false;
    }
    });

    getCanvas().addChild(tryAgain);
    getCanvas().addChild(yestry);
    getCanvas().addChild(noexit);
    getCanvas().addChild(re);
    }
    if (horizontalTiles == 5 && TimeInSeconds == 5) {
    for (MTComponent c : puzzleGroup.getChildren()) {
    c.destroy();
    }
    puzzleGroup.destroy();
    timer.cancel();
    timer.purge();
    puzzleGroup.setVisible(false);
    getscore(counter);
    System.out.println("Score: " + score);
    System.out.println("RECORD: " + timercount.getText());
    re.setPositionGlobal(new Vector3D(mtApp.width / 2,
    mtApp.height / 2 - 150));
    re.setNoStroke(true);
    re.setTexture(imggo);
    re.setVisible(true);

    tryAgain.setPickable(false);
    tryAgain.setNoStroke(true);
    tryAgain.setTexture(ta);
    tryAgain.setVisible(true);

    yestry.setFillColor(new MTColor(0, 255, 255, 150));
    yestry.setStrokeColor(new MTColor(0, 255, 255, 200));
    yestry.setText("Yes");
    clearAllGestures(yestry);
    yestry.setVisible(true);
    getCanvas().addChild(yestry);
    yestry.setPositionGlobal(new Vector3D((mtApp.width / 2) - 100,
    (mtApp.height / 2) + 200, 0));
    yestry.registerInputProcessor(new TapProcessor(mtApp, 2000));

    yestry.addGestureListener(TapProcessor.class,
    new IGestureEventListener() {
    public boolean processGestureEvent(MTGestureEvent ge) {
    TapEvent th = (TapEvent) ge;

    switch (th.getId()) {
    case TapEvent.GESTURE_STARTED:
    break;
    case TapEvent.GESTURE_UPDATED:
    break;
    case TapEvent.GESTURE_ENDED:
    noexit.destroy();


    mtApp.pushScene();
    tryagain = new puzzlescene(mtApp,
    "The Brain Tickler");
    mtApp.addScene(tryagain);
    mtApp.changeScene(tryagain);

    System.out.println("stop now");
    break;
    default:
    break;
    }
    return false;
    }
    });

    noexit.setFillColor(new MTColor(0, 255, 255, 150));
    noexit.setStrokeColor(new MTColor(0, 255, 255, 200));
    noexit.setText("Exit");
    clearAllGestures(noexit);
    noexit.setVisible(true);
    getCanvas().addChild(noexit);
    noexit.setPositionGlobal(new Vector3D((mtApp.width / 2) + 100,
    (mtApp.height / 2) + 200, 0));
    noexit.registerInputProcessor(new TapProcessor(mtApp, 2000));

    noexit.addGestureListener(TapProcessor.class,
    new IGestureEventListener() {
    public boolean processGestureEvent(MTGestureEvent ge) {
    TapEvent th = (TapEvent) ge;

    switch (th.getId()) {
    case TapEvent.GESTURE_STARTED:
    break;
    case TapEvent.GESTURE_UPDATED:
    break;
    case TapEvent.GESTURE_ENDED:
    yestry.destroy();
    tryagain.destroy();
    record.destroy();
    System.exit(0);
    break;
    default:
    break;
    }
    return false;
    }
    });

    getCanvas().addChild(tryAgain);
    getCanvas().addChild(yestry);
    getCanvas().addChild(noexit);
    getCanvas().addChild(re);
    }

    System.out.println("Time is: " + TimeInMinutes + " : "
    + TimeInSeconds);
    }

    and if you really have a free time... here's the full code... but I need to warn you that it won't run because you still need the pictures I used and the library I'm using which is mt4j ..
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by janefabellore; August 26th, 2013 at 12:57 AM. Reason: show the code


  2. #2
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: IndexOutOfBoundsException - HELP! DON’T KNOW EXACTLY WHAT THIS MEANS. :(

    Hello.
    Instead of attaching the image like this it might be better if you post the piece of your code that produced the error along with the stack trace.
    Looking at the exception its clear that you are trying to read a value at an index which is beyond the size of the array/collection.

    Syed.

Similar Threads

  1. Using NetBeans and I have no idea what the error message means...
    By Rick Sebastian in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 20th, 2013, 08:30 PM
  2. Replies: 16
    Last Post: September 11th, 2011, 07:33 AM
  3. help with problem havr no idea what it means
    By mdstrauss in forum Exceptions
    Replies: 4
    Last Post: July 27th, 2009, 12:41 AM

Tags for this Thread