1

我不确定为什么我的应用程序中出现以下错误:

Multiple markers at this line
    - implements 
     android.os.AsyncTask<java.lang.String,java.lang.Void,java.util.ArrayList<java.util.HashMap<java.lang.String,java.lang.String>>>.doInBackground
    - This method must return a result of type ArrayList<HashMap<String,String>>

当我将鼠标悬停在第 195 行的 return 语句上时,我在 Aptana 的弹出窗口中得到了正确的类型。

    public class getResults extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > {

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(
            String... params) {
        // TODO Auto-generated method stub

        //get names from each text box

        ArrayList<HashMap<String, String>> commonFilms = new ArrayList<HashMap<String, String>>();
        ArrayList<HashMap<String, String>> firstFilms = new ArrayList<HashMap<String, String>>();
        ArrayList<HashMap<String, String>> secondFilms = new ArrayList<HashMap<String, String>>();
        String nameOne = searchOne.getText().toString();
        String nameTwo = searchTwo.getText().toString();

        nameOne = nameOne.replace(" ", "_");
        nameTwo = nameTwo.replace(" ", "_");

        String searchOneURL = personURL + nameOne;
        String searchTwoURL = personURL + nameTwo;

        //Hashmap for ListView


        //Create JSON Parser Instanece
        JSONParser jParser = new JSONParser();

        //getting JSON string from url
        JSONObject jsonOne = jParser.getJSONFromUrl(searchOneURL);
        JSONObject jsonTwo = jParser.getJSONFromUrl(searchTwoURL);


        try {
            //Get ID of each person
            idOne = jsonOne.getJSONArray(TAG_ID);
            idTwo = jsonTwo.getJSONArray(TAG_ID);


            String firstID = null;
            String secondID = null;
            for(int i = 0; i < idOne.length(); i++){
                JSONObject iDeeOne = idOne.getJSONObject(i);

                //store each json item in variable
                firstID = iDeeOne.getString(TAG_ID);

            }

            for(int i = 0; i < idTwo.length(); i++){
                JSONObject iDeeTwo = idTwo.getJSONObject(i);

                //store each json item in variable
                secondID = iDeeTwo.getString(TAG_ID);
            }
            String creditURlBase = "http://api.themoviedb.org/3/person";

            String firstCreditURL = creditURlBase + firstID;
            String secondCreditURL = creditURlBase + secondID;

            JSONObject jSon = jParser.getJSONFromUrl(firstCreditURL);


            firstCast = jSon.getJSONArray(TAG_CAST);
            for(int i = 0; i < firstCast.length(); i++){
                JSONObject c = firstCast.getJSONObject(i);
                title = c.getString(TAG_TITLE);

                //ctreate new hashmap
                HashMap<String, String> map = new HashMap<String, String>();

                //and node to map
                map.put(TAG_TITLE, title);
                firstFilms.add(map);

            }

            secondCast = jSon.getJSONArray(TAG_CAST);
            for(int i = 0; i < secondCast.length(); i++){
                JSONObject c = firstCast.getJSONObject(i);
                title = c.getString(TAG_TITLE);

                //create hashmap
                HashMap<String, String> mapTwo = new HashMap<String, String>();

                mapTwo.put(TAG_TITLE, title);
                secondFilms.add(mapTwo);


            }

            if(firstFilms.size() > secondFilms.size()){
                for(int i = 0; i < firstFilms.size(); i++){
                    if(firstFilms.contains(secondFilms.get(i))){

                        HashMap<String, String> mapThree = new HashMap<String, String>();

                        mapThree.put(TAG_TITLE, secondFilms.get(i).toString());
                        commonFilms.add(mapThree);
                    }

                }

            }else{
                for(int i = 0; i < secondFilms.size(); i++){
                    if(secondFilms.contains(firstFilms.get(i))){
                        HashMap<String, String> map = new HashMap<String, String>();
                        map.put(TAG_TITLE, firstFilms.get(i).toString());
                        commonFilms.add(map);
                    }
                }
            }
            return commonFilms;



            }
        catch(JSONException e){
            Log.e("Error", e.toString());
        }

        }


    }



@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.totlayout, menu);
    return true;
}
}

任何帮助,将不胜感激。谢谢

4

1 回答 1

4

那是因为并非您的方法的所有可能退出点都返回一个ArrayList. 特别是,如果你得到一个JSONException

    catch(JSONException e) {
        Log.e("Error", e.toString());
    }

你需要一个return null或一个空的ArrayList. 正如@BalusC 所建议的,另一种选择是声明您的方法来抛出 aJSONException并删除try/catch块或重新抛出它:

    catch(JSONException e) {
        Log.e("Error", e.toString());
        throw e; // Possibly wrap it with a *domain* Exception
    }
于 2012-09-11T01:36:46.970 回答