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

2
  • There is not enough info for us to help. Please provide the code of the adapter. Commented Feb 18, 2013 at 2:07
  • 1
    Why would you think that you COULD cast a HashMap to a String??? Commented Feb 18, 2013 at 2:07

2 Answers 2

4

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 content of that AdaptaverView.

Sign up to request clarification or add additional context in comments.

Comments

1

Please compare the java with real life, you are trying to convert DOG object into Peacock object , that is not possible.

And you should use toString() method of object class for string conversion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.