Java 我不知道为什么我的班级不是';t返回正确的类型。ArrayList<;HashMap<;字符串,字符串>&燃气轮机;
我不确定为什么我的应用程序中出现以下错误:Java 我不知道为什么我的班级不是';t返回正确的类型。ArrayList<;HashMap<;字符串,字符串>&燃气轮机;,java,android,Java,Android,我不确定为什么我的应用程序中出现以下错误: 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 met
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>>
此行有多个标记
-工具
android.os.AsyncTask.doInBackground
-此方法必须返回ArrayList类型的结果
当我将鼠标悬停在第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;
}
}
public类getResults扩展异步任务{
@凌驾
受保护的ArrayList doInBackground(
字符串…参数){
//TODO自动生成的方法存根
//从每个文本框中获取名称
ArrayList commonFilms=新的ArrayList();
ArrayList firstFilms=新的ArrayList();
ArrayList secondFilms=新的ArrayList();
字符串nameOne=searchOne.getText().toString();
String nameTwo=searchTwo.getText().toString();
nameOne=nameOne.replace(“,”);
nameTwo=nameTwo.replace(“,”);
字符串searchOneURL=personURL+nameOne;
字符串searchTwoURL=personURL+nametwor;
//ListView的Hashmap
//创建JSON解析器实例
JSONParser jParser=新的JSONParser();
//从url获取JSON字符串
JSONObject jsonOne=jParser.getJSONFromUrl(searchOneURL);
JSONObject jsonTwo=jParser.getJSONFromUrl(searchTwoURL);
试一试{
//获取每个人的身份证
idOne=jsonOne.getJSONArray(TAG_ID);
idTwo=jsonTwo.getJSONArray(TAG_ID);
字符串firstID=null;
字符串secondID=null;
for(int i=0;isecondFilms.size()){
对于(int i=0;i
任何帮助都将不胜感激。谢谢这是因为并非方法的所有可能退出点都返回
数组列表
。特别是,如果您收到一个JSONException
:
catch(JSONException e) {
Log.e("Error", e.toString());
}
您需要返回null
或一个空的ArrayList
。@BalusC建议的另一种替代方法是声明抛出JSONException
的方法,然后删除try/catch
块,或者重新抛出它:
catch(JSONException e) {
Log.e("Error", e.toString());
throw e; // Possibly wrap it with a *domain* Exception
}
这是因为并非方法的所有可能退出点都返回ArrayList
。特别是,如果您收到一个JSONException
:
catch(JSONException e) {
Log.e("Error", e.toString());
}
您需要返回null
或一个空的ArrayList
。@BalusC建议的另一种替代方法是声明抛出JSONException
的方法,然后删除try/catch
块,或者重新抛出它:
catch(JSONException e) {
Log.e("Error", e.toString());
throw e; // Possibly wrap it with a *domain* Exception
}
如果发生异常,则需要返回。如果发生异常,则需要返回。如果有必要,请将异常包装成另一个。或者如果有必要,请将异常包装成另一个。