java.lang.ArrayIndexOutOfBoundsException错误 - 如何修复?

时间:2018-06-01 07:07:04

标签: android

这是我的代码:

private void genData(){

    List<String> title = Arrays.asList("Android Programing","IOS Programing");
    List<String> childitem = Arrays.asList("hello","hi","what is up");

    lstChild = new TreeMap<>();
    lstChild.put(title.get(0),childitem);
    lstChild.put(title.get(1),childitem);


    lstTitle = new ArrayList<>(lstChild.keySet());

    List<String> titleq = Arrays.asList("Xamarin ");
    List<String> childitemq = Arrays.asList("hello","hi","what is up");

    lstChild = new TreeMap<>();
    lstChild.put(titleq.get(0),childitemq);
    lstChild.put(titleq.get(1),childitemq);
    lstChild.put(titleq.get(2),childitemq);

    lstTitle = new ArrayList<>(lstChild.keySet());
}

private void initItems(){
    items = new String[]{"Home","Who we Are","services","online Marketing","Get free Quote","Contact"};

}

我面临的错误:       at java.util.Arrays $ ArrayList.get(Arrays.java:3769)

  

我想在Xamarin plz帮助中添加6个孩子

1 个答案:

答案 0 :(得分:0)

此列表

List<String> titleq = Arrays.asList("Xamarin ");

只有一个项目。在这里

lstChild.put(titleq.get(0),childitemq);
lstChild.put(titleq.get(1),childitemq);
lstChild.put(titleq.get(2),childitemq);

你得到的不止一件物品。我相信有错误。

更确切地说是lstChild.put(titleq.get(1),childitemq);