This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays.sort

 
susana miranda
Greenhorn
Posts: 9
  • 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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic