【问题标题】:Android: Empty error message in onFailure of AsyncHttpClientAndroid:AsyncHttpClient 的 onFailure 中出现空错误消息
【发布时间】:2011-12-24 16:02:16
【问题描述】:

我使用了一个适用于 Android 的 http 客户端库,可以在这里找到:http://loopj.com/android-async-http/。 问题是当我想处理诸如互联网连接错误之类的故障时。我无法从处理程序方法中获得错误消息:

    AsyncHttpClient client = new AsyncHttpClient();
    client.get(..., params, new JsonHttpResponseHandler() {
        @Override
        public void onSuccess(JSONObject response) {
        }

        @Override
        public void onFailure(Throwable e) {
            Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
        }

为什么 e.getLocalizedMessage() 或 e.getMessage() 为空?

【问题讨论】:

    标签: android asynchronous error-handling httprequest


    【解决方案1】:

    这应该会有所帮助:

                @Override
            public void onFailure ( Throwable e, JSONObject errorResponse ) {
                String msg = "Object *" + e.toString() + "*" + errorResponse.toString();
                new AlertDialog.Builder(MyActivity.this).setMessage(msg).setCancelable(false).setTitle("Fehler").setPositiveButton(R.string.ok, null).create().show();
            }
    
            @Override
            public void onFailure ( Throwable e, JSONArray errorResponse ) {
                String msg = "Array *" + e.toString() + "*" + errorResponse.toString();
                new AlertDialog.Builder(MyActivity.this).setMessage(msg).setCancelable(false).setTitle("Fehler").setPositiveButton(R.string.ok, null).create().show();
            }
    
            @Override
            public void onFailure ( Throwable e, String errorResponse ) {
                String msg = "String *" + e.toString() + "*" + errorResponse;
                new AlertDialog.Builder(MyActivity.this).setMessage(msg).setCancelable(false).setTitle("Fehler").setPositiveButton(R.string.ok, null).create().show();
            }
    

    【讨论】:

      猜你喜欢
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2019-08-26
      • 2021-06-17
      相关资源
      最近更新 更多