首页 > 解决方案 > JsonObjectRequest 既不响应 listener 也不响应 errorListener

问题描述

我的 JsonObjectRequest 没有按照我的指示行事。凌空API会罢工吗?我的日志猫只是说“请求的 URL:http://..”。我的日志猫既没有说“Json Parsing Error:”也没有说“HTTP Request Error:”。请任何人告诉我我做错了什么。

String url = REST_URL + "?seq=" + mLastSeq;
Log.i(DEBUG_TAG, "Requested URL: "+url);
JsonObjectRequest req = new JsonObjectRequest(url, null,
        new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    mLastSeq = response.getInt("last");
                    mNewCount = response.getInt("count");
                    Log.i(DEBUG_TAG, mLastSeq+"");
                    Log.i(DEBUG_TAG, mNewCount+"");
                    if (mNewCount>0) {
                        String title = mCtx.getResources().getString(R.string.app_name);
                        String message = mCtx.getResources().getString(R.string.new_news_alert);
                        showNotification(title, message);
                    }
                } catch (JSONException error) {
                    Log.d(DEBUG_TAG, "Json Parsing Error: " + error.getMessage());
                }
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Log.d(DEBUG_TAG, "HTTP Request Error:" + error.getMessage());
    }

});

标签: android-volleyjsonobjectrequest

解决方案


应用程序可能在其主线程上做了太多工作。


推荐阅读