嗨,我是Android的初学者,我陷入了这个问题。所以我正在尝试使用一个凌空响应对象
private void parseJSONResponse(JSONObject response)
{
int a = jsonObject.getInt("xxx"); //get 1st parameter
String mid = jsonObject.getString("Movieid"); //get an id
String murl = genrate(mid); //send id to genrate method which returns another url
String x=createmovieJSON(murl);//method to create JsonObjectRequest object using the new url and return string.
info.add(new information(a,x)); //pass int and string for generating a card layout
}
createmovieJSON方法如下:
public String createmovieJSON(String strurl)
{
final String[] str=(null); //str[0] contains null
RequestQueue requestQueue = Singelton.instantinate().getRequestqueue();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, strurl,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
str[0] = parseMovieResponse(response); //str[0] contains required string say'abc'
new Toastnotify(getApplicationContext(),str[0]);
}
},
new Response.ErrorListener(){...
});
requestQueue.add(jsonObjectRequest);
new Toastnotify(getApplicationContext(),str[0]);
return(str[0]); //str[0] contains null instead of abc
}
&#39; final String []&#39;在纠正错误时自动创建数组&#34;将str转换为最终的一个元素数组&#34;在onResponse方法。为什么它创建一个数组,而不只是使str最终?(我尝试手动但它给出了相同的错误)。我知道它是一个内部类,因此我必须使它最终但为什么数组?
那么如何将onResponse中str [0]中返回的字符串发送回parseJSONResponse方法中的调用方法?