由于此异常,我的 Android 应用程序崩溃,我不明白为什么会发生此异常:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
下面是我的代码。
private void setAllData(View v)
{
ArrayList<String> idList = new ArrayList<String>();
boolean added=false;
for(String chid:checkedList)
{
SortedSet<String> ts = new TreeSet<String>();
int id=txt2Id.get(chid);
View v1=v.findViewById(id);
if(v1!=null)
{
Log.e("---- Value of v1 ----", v1.getTag().toString());
// I am getting ClassCast exception on the below line
ArrayList<String>vidList=(ArrayList<String>) v1.getTag(id);
if(vidList==null||vidList.size()==0)
{
((CustomFragment) getActivity()).updateTab4List(new ArrayList<String>());
return;
}
else
{
if(!added)
{
idList=vidList;
added=true;
}
else if(idList.size()==0)
{
((CustomFragment) getActivity()).updateTab4List(idList);
return;
}
else
{
ArrayList<String> temp = new ArrayList<String>();
int i=0;
for(String str:idList)
{
if(vidList.contains(str))
temp.add(str);
}
idList=temp;
}
}
}
}
if(checkedList.size()==0)
idList=null;
((CustomFragment) getActivity()).updateTab4List(idList);
}