错误:类型不匹配:无法从ArrayList的&LT转换; Subchild&GT;到ArrayList的&LT;串GT; [英] error: Type mismatch: cannot convert from ArrayList<Subchild> to ArrayList<String>
问题描述
您好我有一个XML文件,我成功之前解析。现在我改变简单的修改在我的XML文件中我得到很多的错误后。如何解决这个错误我不知道我张贴我的我的xml文件中第一次和我使用SAX解析器。
Hi I have one xml file successfully parsed my before. now i am change simple modification in my xml file after i am getting lot of error. how to solve this error i don't know i post my my xml file 1st and am using sax parser.
我有两个微调如果我点击第一个微调其显示为test1,test2的,TEST3然后我选择的Test1其节目test1的子标签名stest1到stest5。如果选择测试2我的第二微调显示stest6到stest10这是我工作的xml文件输出现在我想从我的已经xml文件我sltag显示名称标记在sltag添加一个标签现在我在这里补充我的问题开始。我的问题是如何得到这两个值进入我的sltag我需要单独的字符串值,所以我在我的sltag数组列表通过类并创建类也声明名称和路径后,进入数组列表,那么如何让这两个字符串值,我的目的是,当我选择我想表现出相同的屏幕底部的一些图片我试图让路径字符串值。第二微调值
i have two spinner if i click 1st spinner its shows test1, test2, test3 then i select test1 its shows test1 sub tag name stest1 to stest5. if select test2 my 2nd spinner show stest6 to stest10 this is my working xml file output now i am trying to add one tag in sltag from my xml file already my sltag display name tag now i am add here my problem is started. my problem is how to get both values into my sltag i need separate string value so i passed class in my sltag array list and create class also after declare name and path into array list then how to get both string value My purpose is when i select 2nd spinner value that i want to show some images in same screen bottom i trying to get path string value.
这是我的错误:
1.错误行:类型不匹配:无法从ArrayList中转换成的ArrayList
This is my error: 1. error line: Type mismatch: cannot convert from ArrayList to ArrayList
行
其他Java文件链接的位置:
other java files link here:
推荐答案
您的方法 getSLTag
声明为返回一个的ArrayList&LT;弦乐&GT;
但是变量 sltag
在 xmlTag
类实际上是一个的ArrayList&LT; SubChild方式&gt;
因此,类型不匹配
Your method getSLTag
is declared to return an ArrayList<String>
but the variable sltag
in the xmlTag
class is actually an ArrayList<SubChild>
hence the type mismatch.
所以,为您解答希望得到来自sltag路径字符串额外的评论,您将需要迭代的 SubChild
S中的集合,每个路径添加到一个新的列表字符串,例如:
So to answer your additional comment about wanting to get path string from sltag, you will need to iterate over the collection of SubChild
s and add each path to a new List of Strings, e.g.
public ArrayList<String> getSLTag(String hltag) {
List<String> slTags = new ArrayList<String>();
for(int i = 0; i < xmlTagInfo.size(); i++) {
if( xmlTagInfo.get(i).hltag == hltag ) {
for (SubChild child : xmlTagInfo.get(i).sltag) {
// Your SubChild class actually declares path and name to be an ArrayList of Strings, but surely they should just be Strings?
slTags.add(child.getPath());
}
}
}
return slTags;
}
这篇关于错误:类型不匹配:无法从ArrayList的&LT转换; Subchild&GT;到ArrayList的&LT;串GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!