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());
}
}
Re: Does this compile on your machine
One problem is Collections.reverseOrder(array); reverseOrder(int[] i) is contained within the Collections class.
Re: Does this compile on your machine
Plus the sort methods work on Collections only.
Re: Does this compile on your machine
All Collections methods only work on collections. Use the methods from the Arrays class.
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);
Re: Does this compile on your machine
Re: Does this compile on your machine
System_Error what did the compiler say?
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:
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.
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.