我正在尝试从数组列表中复制元素,然后将其传递给我的活动。同样在我正在检查gfList的if语句中,0 Java抱怨无法从GroupedFeed转换为int。如果有人知道问题出在哪里并且可以告诉我如何将元素复制并粘贴到我的活动中,我将不胜感激。提前致谢!这是我的代码:

 // I created my for loop but that did not work
        GroupedFeed findFeed(String locateSport){
            if ((int) gfList != 0){
                for(int i = 0; i != gfList.size();i++){
                    if(gfList[i].category.equalsIngnoreCase(locateSport)){

                    }
                }
                return gfResult;
            }
        }

        public boolean onChildClick(ExpandableListView parent,
                android.view.View v, int groupPosition, int childPosition,
                long id) {
            switch (groupPosition){
                case 0:
                    switch (childPosition){
                        case 0:
                            // gfResult = findFeed("Men's Baseball");
                            Baseball();  // pass gfResult
                            break;
                    }
                return false;
            }

            private void Baseball() {
                Intent myIntent = new Intent(MainActivity.this, Baseball.class);
                startActivity(myIntent);
            }
        });
        Main myMain = new Main();
        try {
            //  AssetManager aMan = getAssets();
            this.gfList = myMain.loadRSS();
        } catch (Exception e) {
            System.out.println("Hosed");
        }
    }
}


这是我的数组列表:

this   Main  (id=831962574768)
groupedFeeds    ArrayList  (id=831963150464)
    array   Object[12]  (id=831963153088)
        [0] GroupedFeed  (id=831963152968)
            category    "Women's Golf" (id=831962986192)
            feeds   ArrayList  (id=831963152992)
        [1] GroupedFeed  (id=831963153592)
            category    "Volleyball" (id=831962991720)
            feeds   ArrayList  (id=831963153616)
        [2] GroupedFeed  (id=831963153744)
            category    "Men's Soccer" (id=831962996544)
            feeds   ArrayList  (id=831963153768)
        [3] GroupedFeed  (id=831963153896)
            category    "Women's Soccer" (id=831963006320)
            feeds   ArrayList  (id=831963153920)
        [4] GroupedFeed  (id=831963154864)
            category    "Men's Golf" (id=831963016488)
            feeds   ArrayList  (id=831963154888)
        [5] GroupedFeed  (id=831963155072)
            category    "Men's Cross Country" (id=831963036816)
            feeds   ArrayList  (id=831963155096)
        [6] GroupedFeed  (id=831963155224)
            category    "Women's Cross Country" (id=831963041984)
            feeds   ArrayList  (id=831963155248)
        [7] GroupedFeed  (id=831963155472)
            category    "Men's Bowling" (id=831963093056)
            feeds   ArrayList  (id=831963155496)
        [8] GroupedFeed  (id=831963155712)
            category    "Women's Bowling" (id=831963098224)
            feeds   ArrayList  (id=831963155736)
        [9] GroupedFeed  (id=831963155864)
            category    "Women's Basketball" (id=831963170720)
            feeds   ArrayList  (id=831963155888)
        [10]    GroupedFeed  (id=831963157504)
            category    "Men's Basketball" (id=831963299944)
            feeds   ArrayList  (id=831963157528)
        [11]    null
    modCount    11
    size    11
loader  RSSLoader  (id=831962575480)
aMan    AssetManager  (id=831962469744)

最佳答案

尽管显然不是整数,但您不包括在其实例化gfList的位置。我想你的意思是打电话给gfList.size() != 0!gfList.isEmpty()

GroupedFeed findFeed(String locateSport){
    if ((!gfList.isEmpty()){
        for (int i = 0; i != gfList.size();i++){
            if (gfList.get(i).category.equalsIgnoreCase(locateSport)){
                return gfList.get(i);
            }
        }
    }
    return null;
}


然后,在调用此方法时处理可能为空(找不到匹配项)的可能性

09-10 00:52