首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未执行AsyncHttpClient OnSuccess

未执行AsyncHttpClient OnSuccess
EN

Stack Overflow用户
提问于 2015-06-03 17:41:00
回答 2查看 2K关注 0票数 1

这是我在控制台中得到的:

代码语言:javascript
复制
onSuccess(int, Header[], JSONObject) was not overriden, but callback was received

我验证过了,文件被上传到服务器上。

这是我的代码,应用程序不会抱怨:

代码语言:javascript
复制
public void uploadImage() {
        //Create a new RequestParams that will send paremeters with our AsyncHttpClient request.
        RequestParams data = new RequestParams();

        //Adding our image to the parameters.
        File image = new File(imgPath);
        try {
        data.put("image", image);
    } catch(FileNotFoundException e) {}
    //Create a new AsyncHttpClient request.
    //here we're sending a POST request, the first parameter is the request URL
    // then our RequestParams, in our case data and then a Json response handler.
    AsyncHttpClient client = new AsyncHttpClient();
    client.post(FILE_UPLOAD_URL, data, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(int statusCode, Header headers[], JSONArray success) {
            try {
                JSONObject data = success.getJSONObject(0);
                String m = data.getString("message");
                Toast.makeText(UploadPhotoTest.this, m, Toast.LENGTH_LONG).show();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
}

这是我导入的内容,如果它是相关的:

代码语言:javascript
复制
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

我的问题是OnSuccess中的任何东西都不会被执行。我在OnSuccess try和catch中放置了一个日志,但什么也没有打印出来。我该如何解决这个问题呢?

EN

回答 2

Stack Overflow用户

发布于 2016-03-04 06:29:25

public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

这对我很有效。

票数 1
EN

Stack Overflow用户

发布于 2022-02-19 12:46:33

在所有地方使用JSONObject,在JSONArray中都会得到"Success“响应。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30616354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档