Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Java Arrays.sort throws exception

Reply
Thread Tools

Java Arrays.sort throws exception

 
 
captain
Guest
Posts: n/a
 
      05-14-2008
When the number of elements gets above around 2700 the Arrays.sort
inside the Collections.sort throws an exception:

java.lang.ArrayIndexOutOfBoundsException

Any ideas?

Thanks
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      05-14-2008
On Wed, 14 May 2008 07:37:00 -0700 (PDT), captain
<(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
said :

>When the number of elements gets above around 2700 the Arrays.sort
>inside the Collections.sort throws an exception:
>
>java.lang.ArrayIndexOutOfBoundsException


We will have to see your code. In the meantime have a look at
http://mindprod.com/jgloss/sort.html
to learn how to write sorts.

Presumably your Comparator is doing some indexing which is failing.
Look carefully at the stack trace for the precise line that is
failing.

--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      05-14-2008
captain wrote:
> When the number of elements gets above around 2700 the Arrays.sort
> inside the Collections.sort throws an exception:
>
> java.lang.ArrayIndexOutOfBoundsException
>
> Any ideas?
>
> Thanks


Yeah, it's line 115 of your code. Just fix that up and you'll be ok.
 
Reply With Quote
 
captain
Guest
Posts: n/a
 
      05-14-2008
I am brand new here and don't mean to be flippant, but is this a joke?

On May 14, 12:48*pm, Mark Space <(E-Mail Removed)> wrote:
> captain wrote:
> > When the number of elements gets above around 2700 the Arrays.sort
> > inside the Collections.sort throws an exception:

>
> > java.lang.ArrayIndexOutOfBoundsException

>
> > Any ideas?

>
> > Thanks

>
> Yeah, it's line 115 of your code. *Just fix that up and you'll be ok.


 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      05-14-2008
captain <(E-Mail Removed)> writes:

>> Yeah, it's line 115 of your code. *Just fix that up and you'll be ok.


> I am brand new here and don't mean to be flippant, but is this a joke?


Yes, it's a joke, with a point. The point being that we can't find the
problem if you don't show us code that exhibits the problem.

In the unlikely event that Arrays.sort had a bug that showed already
at 2700 elements, and that we knew of it, we could, in theory, guess
that it was that bug you were hitting.

As someone else said, the probability of the bug being in the standard
library vs. the probability of it being in your code suggests that you
should just go ahead and show your code ... or rather show a nicely
reduced example without unnecessary distractions but which still
exhibits the problem.

Often, the act of cutting down to a SSCCE (Small Self-Contained Compilable
Example) will reveal the bug along the way.

Also remember to note which JVM version you are running on. If the bug
is related to the standard library, then that might also be important.

In general, when you need help with a programming problem, you should
provide enough information for us to do the "Three R's". We need to be able
to:
Reproduce the problem: Say what you do. Be precise (give a SSCCE
that exhibits the problem). Further details are good.
Recognize the problem: Say what happens that you consider as the problem.
It might be expected behavior. It might not happen to to someone with
a different configuration.
Repair the problem: Say what you expected to happen. Can't fix the
problem if we don't know what to fix it *to*.

/L
--
Lasse Reichstein Nielsen - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
Andrea Francia
Guest
Posts: n/a
 
      05-14-2008
captain wrote:
> I am brand new here and don't mean to be flippant, but is this a joke?

If you don't post your code nobody can help you.
 
Reply With Quote
 
captain
Guest
Posts: n/a
 
      05-14-2008
Eric,

Thank you very much for your response.

My code:

List adminItems = new ArrayList();

loop:
adminItems.add(administeredItem);

Collections.sort(adminItems);

------------
Collections.class (Sun Code):

public static void sort(List list) {
Object a[] = list.toArray();
Arrays.sort(a); // THROWS EXCEPTION
ListIterator i = list.listIterator();
for (int j=0; j<a.length; j++) {
i.next();
i.set(a[j]);
}
}

Thanks,

Fred

On May 14, 11:59*am, Eric Sosman <(E-Mail Removed)> wrote:
> captain wrote:
> > When the number of elements gets above around 2700 the Arrays.sort
> > inside the Collections.sort throws an exception:

>
> > java.lang.ArrayIndexOutOfBoundsException

>
> > Any ideas?

>
> * * *It is conceivable that the sort() implementation has a
> bug. *But it is far, Far, FAR more probable that the bug is
> in the code you haven't shown ...
>
> --
> (E-Mail Removed)


 
Reply With Quote
 
captain
Guest
Posts: n/a
 
      05-14-2008
Roedy,

Thank you very much for your response.

My code:

List adminItems = new ArrayList();

loop:
adminItems.add(administeredItem);

Collections.sort(adminItems);

------------
Collections.class (Sun Code):

public static void sort(List list) {
Object a[] = list.toArray();
Arrays.sort(a); // THROWS EXCEPTION
ListIterator i = list.listIterator();
for (int j=0; j<a.length; j++) {
i.next();
i.set(a[j]);
}
}

Thanks,

Fred




On May 14, 11:15*am, Roedy Green <(E-Mail Removed)>
wrote:
> On Wed, 14 May 2008 07:37:00 -0700 (PDT), captain
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone who
> said :
>
> >When the number of elements gets above around 2700 the Arrays.sort
> >inside the Collections.sort throws an exception:

>
> >java.lang.ArrayIndexOutOfBoundsException

>
> We will have to see your code. *In the meantime have a look athttp://mindprod.com/jgloss/sort.html
> to learn how to write sorts.
>
> Presumably your Comparator is doing some indexing which is failing.
> Look carefully at the stack trace for the precise line that is
> failing.
>
> --
>
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com


 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      05-14-2008
Lasse Reichstein Nielsen wrote:
> captain <(E-Mail Removed)> writes:
>
>>> Yeah, it's line 115 of your code. Just fix that up and you'll be ok.

>
>> I am brand new here and don't mean to be flippant, but is this a joke?

>
> Yes, it's a joke, with a point. The point being that we can't find the
> problem if you don't show us code that exhibits the problem.
>


Pretty much. And a cursor search of this news group for various "help"
topics always yields the same replies:

1. Post an SSCCE
2. Post an SSCCE
3. Post an SSCCE

Assuming you did a search first to try to solve your problem, you should
have hit these. So I can only conclude that you did very little
research of your own before posting your message. And it's getting
irritating to keep making the exact same reply to each of these requests.

Post an SSCCE.
 
Reply With Quote
 
captain
Guest
Posts: n/a
 
      05-14-2008
This is my very first post and I am not up on the etiquete yet.

I realize that the problem must be in my code. Actually, I didn't
right this code, I inherited it. I have a lot of programming
experience but not in this particular environment.

Here, a list is populated in a loop and then Collections.sort is
called on that list. I would like to know what the possible problems
may be, what to look for.

Thanks

On May 14, 2:18*pm, Lasse Reichstein Nielsen <(E-Mail Removed)> wrote:
> captain <(E-Mail Removed)> writes:
> >> Yeah, it's line 115 of your code. *Just fix that up and you'll be ok.

> > I am brand new here and don't mean to be flippant, but is this a joke?

>
> Yes, it's a joke, with a point. The point being that we can't find the
> problem if you don't show us code that exhibits the problem.
>
> In the unlikely event that Arrays.sort had a bug that showed already
> at 2700 elements, and that we knew of it, we could, in theory, guess
> that it was that bug you were hitting.
>
> As someone else said, the probability of the bug being in the standard
> library vs. the probability of it being in your code suggests that you
> should just go ahead and show your code ... or rather show a nicely
> reduced example without unnecessary distractions but which still
> exhibits the problem.
>
> Often, the act of cutting down to a SSCCE (Small Self-Contained Compilable
> Example) will reveal the bug along the way.
>
> Also remember to note which JVM version you are running on. If the bug
> is related to the standard library, then that might also be important.
>
> In general, when you need help with a programming problem, you should
> provide enough information for us to do the "Three R's". We need to be able
> to:
> *Reproduce the problem: Say what you do. Be precise (give a SSCCE
> * that exhibits the problem). Further details are good.
> *Recognize the problem: Say what happens that you consider as the problem.
> * It might be expected behavior. It might not happen to to someone with
> * a different configuration.
> *Repair the problem: Say what you expected to happen. Can't fix the *
> * problem if we don't know what to fix it *to*.
>
> /L
> --
> Lasse Reichstein Nielsen *- *(E-Mail Removed)
> *DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
> * 'Faith without judgement merely degrades the spirit divine.'


 
Reply With Quote
 
 
 
Reply

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is an exception specification needed if the method throws and catchesits own exception? elcapitan666@gmail.com C++ 2 11-27-2007 04:01 AM
Java Regular Expression throws StackOverflow Exception sravan Java 2 09-03-2004 08:58 PM
Re: session.abandon throws 'invalid view state' exception in netscape Cowboy \(Gregory A. Beamer\) ASP .Net 1 05-16-2004 02:31 AM
Exception Exception is not compatible with throws clause in Runnable.run() Chris Miller Java 4 11-22-2003 03:11 PM
XmlValidatingReader throws exception for SAOP-ENV:encodingStyle attribute Himmat Dhange ASP .Net 0 08-26-2003 08:28 PM



Advertisments