|
-
Jun 13th, 2005, 01:38 PM
#1
Thread Starter
Frenzied Member
Does this compile on your machine{Resolved}
Ok, I know there is nothing wrong with what I've got(maybe I'm wrong but I doubt it), but it wont compile. It says it can't resolve these two methods:
Collections.sort(int[])
Collections.reverseOrder(int[]);
Code:
/*
* ReverseArray.java
* Created on June 13
*/
import java.util.*;
/**
* @author
* @version
**/
class ReverseArray
{
/*Instance variable*/
private int[] intArray;
/**Class constructor*/
public ReverseArray()
{
super();
}
/**Get the private instance variable
*@return intArray array of ints
*/
public int[] getArray()
{
return intArray;
}
/**Sort and print out the array in ascending order
*@param array int[] array
*@return void
*/
public void sortAscending(int[] array)
{
System.out.println("<---------------Ascending Order-------------->");
Collections.sort(array);
for (int i=0; i<array.length; i++)
{
System.out.println("array[" + i + "]= " + array[i]);
}
}
/**Sort and print out the array in descending order
*@param array int[] array
*@return void
*/
public void sortDescending(int[] array)
{
System.out.println("<---------------Descending Order-------------->");
Collections.reverseOrder(array);
for (int i=0; i<array.length; i++)
{
System.out.println("array[" + i + "]= " + array[i]);
}
}
/**Main method
*@param args command line args
*@return void
*/
public static void main(String[] args)
{
ReverseArray ra = new ReverseArray();
ra.sortAscending(ra.getArray());
ra.sortDescending(ra.getArray());
}
}
Last edited by System_Error; Jun 14th, 2005 at 08:47 PM.
-
Jun 13th, 2005, 08:24 PM
#2
Dazed Member
Re: Does this compile on your machine
One problem is Collections.reverseOrder(array); reverseOrder(int[] i) is contained within the Collections class.
-
Jun 13th, 2005, 08:28 PM
#3
Dazed Member
Re: Does this compile on your machine
Plus the sort methods work on Collections only.
-
Jun 14th, 2005, 02:53 AM
#4
Re: Does this compile on your machine
All Collections methods only work on collections. Use the methods from the Arrays class.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 14th, 2005, 09:56 AM
#5
Thread Starter
Frenzied Member
Re: Does this compile on your machine
The reason I went with the collection class was because I couldn't get the array class to work.
It said it had a problem with this:
Arrays.sort(array);
-
Jun 14th, 2005, 10:00 AM
#6
Re: Does this compile on your machine
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 14th, 2005, 06:58 PM
#7
Dazed Member
Re: Does this compile on your machine
System_Error what did the compiler say?
-
Jun 14th, 2005, 08:42 PM
#8
Thread Starter
Frenzied Member
Re: Does this compile on your machine
Sorry for not getting back to you guys. Take this small code snippet:
Code:
import java.util.*;
class SortTest
{
public static void main(String[] args)
{
String[] letters = {"c","b","a"};
Arrays.sort(letters);
}
}
That should compile right?
Well it doesn't.
I think something is wrong with the compiler. I have similar problems when dealing with graphics. Anytime I try to set the color of something(Say a JLabel or any component), or have anything in the paint method, the compiler goes crazy. It will give me errors on statements that aren't even in the program. For instance, I might set the color of a JLabel, to lets say blue. It will give me compile errors telling me it can't find the symbol yellow in Color.yellow when it's not even in the program. It has a long list of them like that.
Also, I do have some code I wrote a long time ago that uses the arrays.sort method, and it compiled fine back then. I still have the class file and source, but when I try to compile it again, it now gives me an error.
Anyways, here's the error message:
-
Jun 14th, 2005, 08:45 PM
#9
Thread Starter
Frenzied Member
Re: Does this compile on your machine
I think I see the problem. Look at the bottom of the error message. I have a file called Arrays.java. I believe it thought I was calling that class. I'll try and delete it.
-
Jun 14th, 2005, 08:46 PM
#10
Thread Starter
Frenzied Member
Re: Does this compile on your machine
Yep, that was it. I hate it when it's something that simple. Took me forever to figure it out when it was right in front of me.
Sorry guys, and thank you very much for helping out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|