android-volley - 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());
}
});
解决方案
应用程序可能在其主线程上做了太多工作。
推荐阅读
- qt - QML QtCharts CandlestickSeries.append() 返回 false
- asp.net-core - 如何使用 Process(System.Diagnostics.Process)在 asp.net core mvc 应用程序中运行工作服务应用程序?
- ios - Swift 5 API 调用数据变量 nil 但 API 证明有效
- javascript - react-highcharts-官方懒加载数据
- c++ - 打印时字符串的每个第一个字符都有空格
- android - 如何在android数据绑定中将常量传递给onClick侦听器
- css - CSS 网格间距
- rxjs - 为什么switchMap在返回简单数组时不需要observable
- php - Horde Gmail OAuth2 身份验证失败
- r - 工具 subset_taxa 的错误代码;dimnames(x) <- dn 中的错误:“dimnames”[1] 的长度不等于数组范围