This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays.sort

 
susana miranda
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have the following code:



and when compiling...

%/SCJP/exercises$ javac TestSortCollections.java
TestSortCollections.java:37: cannot find symbol
symbol : method sort(Dog[])
location: class Arrays
Arrays.sort(myDogs);
^
1 error


I can't understand why, I am implementing Comparable and also compareTo, what is the problem with Arrays.sort ?

Thnaks so much.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you don't have a class called "Arrays" in your classpath.
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is fine and below is the output:

 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

The error means that, your compiler is picking a Arrays class which is not having the sort method defined within it.
Please make sure, you don't have any Arrays class on the class-path.

Additionally, for the more meaningful output, i will suggest you over-load the toString() method in Dog class like this,


It will surely produce a more meaningful output for you which you desire.

Hope this helps,

 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Arrays" is a system class and it must be in placed.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Make sure you don't have a class called "Arrays" in your classpath.

Or use fully qualified name:
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For sure, the Arrays class he is using is conflicting with the collections Array class. Correctly said above, use the
fully qualified package name.

Hope this helps,
 
susana miranda
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes!! what the.. , I had a Arrays class in the same directory a was trying to compile.

I used the qualified package name and it compiles!

Ok! Thanks so much to everybody!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic