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...

Read the entire entry, it tells you what's expected of classes implementing the interface.

So im going to have to have

implements Comaparable

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

So im going to have to have

implements Comaparable

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

yeah implement Comparable interface in ur Photo class and override ur compareTo method..

try to understand this..
http://www.javapractices.com/topic/TopicAction.do?Id=10

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.