BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 11-26-2007, 02:54 AM   #1 (permalink)
New Member
 
Join Date: Nov 2007
Model: NA
PIN: N/A
Carrier: NA
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down java.lang.IndexOutOfBoundsException

Please Login to Remove!

Hi All,

I've developed a mobile application and tested it on various mobile phones (nokia, motorola, palm, etc) and it works without problem.

Problem 1:

However, when I tried running it on a BlackBerry 8700, after navigating around my application for a while, the BlackBerry complains "Uncaught exception: java.lang.IndexOutOfBoundsException" and closes my application.

I am 90% sure the problem is not from the application because:
1) There is no fixed sequence to reproduce the problem. The exception occurs as and when it likes.
2) There is no problem at all with any other phone I tested.

Problem 2:

I can't reproduce this problem on the BlackBerry simulator (in debug mode through netbeans). Heck! I can't even get the simulator to run properly! My application requires http connection. I've already started the BlackBerry MDS. Sometimes the http connection is ok. Sometimes I get http 400. Sometimes I get http 500. all in the same session! wat the $@!%$#! is going on here?
Offline  
Old 11-26-2007, 10:05 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

well without seeing alot of the code, all we can do is guess. for #1: I'd look at all your container references (arrays, vectors, stacks), indexOutOfBounds means you're trying to access an index within a container where index > container.size()

guess for #2: Look to see that you're terminating your connections and streams properly, there can be some strangeness if you don't
Offline  
Old 11-26-2007, 05:00 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jul 2007
Model: 8800
PIN: N/A
Carrier: TDC
Posts: 115
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

im 95% sure that if u follow the above posters advice you will find that u have made a tiny error

However... once i had a similar exception which was due to the Blackberry for some superstrange reason included the code which i had uncommented. Try to erase all comments from your software (or at least the affected module)
Offline  
Old 11-26-2007, 08:38 PM   #4 (permalink)
New Member
 
Join Date: Nov 2007
Model: NA
PIN: N/A
Carrier: NA
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Re: java.lang.IndexOutOfBoundsException

thx bemshaswing and genvej for the response.

I looked thru the code before posting here. I can't see anything wrong (that of course doesn't mean there's nothing wrong). And I'll explain why I don't think it is a simple coding error.

1) If it is really due to accessing an index beyond the size of a container, the error should happen consistently (e.g. after the same number of menu accesses, or in the same module). This is not the case. The exception happens as and when it likes. It doesn't even follow a fixed number of minutes/seconds. I can use it fine for 5 mins and then the next menu I choose it gives me index out of bounds. I can use it for less then 1 min, and then I get index out of bounds. I can be anywhere inside my midlet before I get index out of bounds.

2) If its due to container references in the code, it will happen in all the other phones as well. There is no reason why accessing an index that is out of bounds should continue to work properly on a Nokia, Motorola or Palm.

I think the problem is due to some behavior of the Java VM which is manufacturer specific. In this case, its the BlackBerry.

I can't post any code because, as I mentioned, there is no specific module that cause this problem. To post the code for debugging would mean to post the entire project.

genvej,

I loaded a .jar file onto the device. Is there a way for a comment to end up in the blackberry through a .jar file?

Does anybody know how to place a catch block at the highest level for a J2ME midlet? For normal java programs, one can do so in the main() method. But for J2ME, I don't know how to do this.
Offline  
Old 12-18-2007, 03:09 AM   #5 (permalink)
New Member
 
Join Date: Nov 2007
Model: NA
PIN: N/A
Carrier: NA
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: java.lang.IndexOutOfBoundsException

Finally solved it
...
...
...
Don't you just hate forums where people make such a comment and left it at that (without a description of the solution)?
...
...
...
And since i hate such a forum as well, here's what happened:

First of all, it isn't as random as I thought. My midlet has a main menu. The exception happens when SOME of the currently displayed Displayable tries to rebuild the main menu (before setting the main menu as the next displayable). Why it happens with some and not others, I still have no idea :(

The code looks something like this:

Code:
class MainMenu extends List {
    void clearList() {
        try {
            for(int i = this.size() - 1; i >= 0; i--) {
                this.delete(i); // exception somewhere here
            }
        } catch (Exception ex) { // debugging only }
    }
    void rebuildList () {
        this.clearList();
        try {
            ...
            this.append(...);
            this.append(...); // exception somewhere here
            this.append(...);
            ...
        } catch (Exception ex) { // debugging only }
    }
}

class SomeDisplay extends Canvas /* (or List, or any other displayable) */ {
    private class SomeCommandListener implements CommandListener {
         public void commandAction(Command cmd, Displayable disp) {
             ...
             mainMenu.rebuildList();
             ...
    }
}
During the delete, for some strange reason, the index becomes out of bounds even though i is always between zero and this.size() and no element is ever removed outside of the method.

During the build, its even more strange that an append() will cause the exception...

Anyways, the code for clearList() is a little strange and I changed it to this.deleteAll() which solved all my problems.

But I would still appreciate it if somebody can tell me why this is happening.


As for the %$@%$# network simulator, I don't know why some parts of the HTTP request does not reach my JSP servlet anybody has any idea?

Last edited by snoopyeo : 12-18-2007 at 03:21 AM.
Offline  
Old 12-18-2007, 03:38 AM   #6 (permalink)
New Member
 
Join Date: Nov 2007
Model: NA
PIN: N/A
Carrier: NA
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Re: java.lang.IndexOutOfBoundsException

btw, the IndexOutOfBoundsException problem happens only on the device. It is not reproducible on the blackberry simulator.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.