Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

UnsortedList$Link cannot be cast to java.lang.String error help

$
0
0
Hi,

I am currently working on a Priority Queue that enqueues an element and a priority. My getHighest method works but it will not allow me to actually print out the priority and I continue to get an -

Exception in thread "main" java.lang.ClassCastException: UnsortedList$Link cannot be cast to java.lang.String
at Main.main(Main.java:82)

error message. My method in my Queue class is

public E getHighest() throws EmptyQueueException {
		if (isEmpty()){
			throw new EmptyQueueException("Empty Queue");
		}
		else{
			int maximum_Size = 100;
			Link<E> front = null;

			for(Link<E> element: List){
				if (element.getPriority() < maximum_Size){
					maximum_Size = element.getPriority();
					front = element;
				}
			}

			return (E) front;
		}


	}
}



Also my tester class contains this line of code that I am using to try to print the priority without actually dequeueing
it completely from the queue.

try {
					System.out.println("The highest priority is " + x.getHighest());}
				catch (EmptyQueueException e)
				{
					System.out.println("Error, no Strings");

				}
				      
			

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>