Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
                                     long id) {
                TextView clickedView = (TextView) view;
                /* Line 79 */ String selectedRouteName = (String) parentAdapter.getItemAtPosition(position);
                String temp = selectedRouteName.substring(0, 2);

Error shown is:

02-18 01:56:53.676: E/AndroidRuntime(821): java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
02-18 01:56:53.676: E/AndroidRuntime(821):  at com.coltonnicotera.londontransitguide.SchedulesActivity$1.onItemClick(SchedulesActivity.java:79)

Not sure what is causing this, I found java.lang.String cannot be cast to java.util.HashMap exception and it seems that I'm doing everything right.

share|improve this question
There is not enough info for us to help. Please provide the code of the adapter. – Wenhui Feb 18 at 2:07
1  
Why would you think that you COULD cast a HashMap to a String??? – Hot Licks Feb 18 at 2:07

2 Answers

up vote 4 down vote accepted

It means that parentAdapter.getItemAtPosition(position) is returning a HashMap instance, which you're trying to convert to a string with the line String selectedRouteName = (String) parentAdapter.getItemAtPosition(position);

You should check the contents of that AdaptaverView.

share|improve this answer

Plz compare the java with real life, you are trying to convert DOG object into Peacock object ... how can it possible? And why r you not using .toString() method of object class for string

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.