I have a Photoalbum class and a Photo class.
The Photoalbum class obviously holds a bunch of photos in an array.
Each photo has a subject, location, date, and path.

I need to make a method to search for a a photo with a certain String path.

I tried:

public void SearchPho(String photoFile)
	{
	int index = Arrays.binarySearch(alb, photoFile );
	System.out.println (index);
	}

This gave me this error:
Exception in thread "main" java.lang.ClassCastException: Photo cannot be cast to java.lang.Comparable
at java.util.Arrays.binarySearch0(Arrays.java:2003)
at java.util.Arrays.binarySearch(Arrays.java:1946)
at PhotoAlbum.SearchPho(PhotoAlbum.java:62)
at TestAlbum.main(TestAlbum.java:17)

Any assistance?
(alb is my photo album array)

have your class Photo implement Comparable in some way.
Read the JDK documentation (and especially the API documentation for the Comparable interface) on how to do that, as well as the Java tutorial and your instructional material your teachers told you to buy.

Hmm. My book didnt really seem to help me.

Let me take a look at the Comparable API real quick but I had done that earlier and it hadnt helped...

So im going to have to have

implements Comaparable

and then make a compareTo method or something like the Photo Class?

This article has been dead for over six months. Start a new discussion instead.