简体   繁体   English

Android java.util.HashMap无法转换为java.lang.String

[英]Android java.util.HashMap cannot be cast to java.lang.String

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. 不知道是什么原因造成的,我发现java.lang.String无法强制转换为java.util.HashMap异常 ,而且看来我所做的一切都正确。

It means that parentAdapter.getItemAtPosition(position) is returning a HashMap instance, which you're trying to convert to a string with the line 这意味着parentAdapter.getItemAtPosition(position)返回一个HashMap实例,您正在尝试将其转换为带有以下内容的字符串:

String selectedRouteName = (String) parentAdapter.getItemAtPosition(position);

You should check the content of that AdaptaverView . 您应该检查那个AdaptaverView的内容。

Please compare the java with real life, you are trying to convert DOG object into Peacock object , that is not possible. 请将Java与现实生活进行比较,您正在尝试将DOG对象转换为Peacock对象,这是不可能的。

And you should use toString() method of object class for string conversion. 并且您应该使用对象类的toString()方法进行字符串转换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassCastException:无法将java.util.HashMap强制转换为java.lang.String - java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String java.lang.String 无法转换为 java.util.HashMap - java.lang.String cannot be converted to java.util.HashMap WedDriverException:初始化RemoteWebDriver时无法将java.util.HashMap强制转换为java.lang.String - WedDriverException : java.util.HashMap cannot be cast to java.lang.String when initializing RemoteWebDriver java.util.HashMap 不能投(android studio, firebase,java) - java.util.HashMap cannot be cast (android studio, firebase,java) java.lang.ClassCastException:java.util.HashMap $ EntrySet无法转换为java.util.HashSet - java.lang.ClassCastException: java.util.HashMap$EntrySet cannot be cast to java.util.HashSet java.lang.ClassCastException: java.util.HashMap$EntrySet 不能转换为 java.util.Map$Entry - java.lang.ClassCastException: java.util.HashMap$EntrySet cannot be cast to java.util.Map$Entry java.lang.ClassCastException:java.util.HashMap无法强制转换为java.lang.Comparable - java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.Comparable 无法将java.util.HashMap强制转换为java.util.ArrayList - java.util.HashMap cannot be cast to java.util.ArrayList java.util.hashmap无法转换为java.util.list - java.util.hashmap cannot be cast to java.util.list java.lang.ClassCastException:java.util.HashMap无法转换为自定义数据类 - java.lang.ClassCastException: java.util.HashMap cannot be cast to custom data class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM