error: Type mismatch: cannot convert from ArrayList<Subchild> to ArrayList<String>

ぃ、小莉子 提交于 2019-12-25 02:16:17

问题


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.

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.

This is my error: 1. error line: Type mismatch: cannot convert from ArrayList to ArrayList

line

source link: http://paste.org/42566

other java files link here:

http://paste.org/42567

http://paste.org/42568

http://paste.org/42569


回答1:


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.

So to answer your additional comment about wanting to get path string from sltag, you will need to iterate over the collection of SubChilds 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;
}


来源:https://stackoverflow.com/questions/8574402/error-type-mismatch-cannot-convert-from-arraylistsubchild-to-arrayliststrin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!