android User-space exception detected!

0

I am trying to connect my android app with a web service in ASP.Net to update data. The issue is that, from what I understand, the connection is established, but the responseBody returns empty and the ResultadoObject to null is created. I'm right? Any possible clue to the cause or solution? Thanks in advance.

Use AsyncHttpClient ()

Debugging receipt of these values:

  

str="", responseBody = {byte [0] @ 5870}, statusCode: 200

client.post(url, requestParams, new AsyncHttpResponseHandler(){
  @Override
  public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
      System.out.println("onSuccess");
      String str = null;
      try {
          str = new String(responseBody, "UTF-8");
      }
      catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      }
      if (str != null)
      {
          ResultadoObject resultado = null;
          try {
             resultado = new ResultadoObject(new JSONObject(str));
          } catch (JSONException e) {
             e.printStackTrace();
          }
          if (resultado.Flag != 0 && resultado.IDMantenimiento != 0)
          {
             loading = false;
             progressDialog.dismiss();
             cambios = true;
             getMantenimiento(resultado.IDMantenimiento);
          }
  

User-space exception detected!

     

java.lang.NullPointerException: Attempt to read from field 'int   com.model.ResultadoObject.Flag 'on a null object reference at   com.activities.MaintenanceEditActivity $ 7.onSuccess (MaintenanceEditActivity.java:791)   at   com.loopj.android.http.AsyncHttpResponseHandler.handleMessage (AsyncHttpResponseHandler.java:351)   at   com.loopj.android.http.AsyncHttpResponseHandler $ ReplyHandler.handleMessage (AsyncHttpResponseHandler.java:510)   at android.os.Handler.dispatchMessage (Handler.java:105) at   android.os.Looper.loop (Looper.java:164) at   android.app.ActivityThread.main (ActivityThread.java:6541) at   java.lang.reflect.Method.invoke (Native Method) at   com.android.internal.os.Zygote $ MethodAndArgsCaller.run (Zygote.java:240)   at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767) "

    
asked by Juan 13.04.2018 в 10:44
source

1 answer

-1

The problem is that you are really getting a null value for result:

   resultado = new ResultadoObject(new JSONObject(str));

this is because str probably has no value or is not a Json object, for this you must review the result of the request.

To avoid the error add the validation resultado != null :

...
...
      if (resultado != null && resultado.Flag != 0 && resultado.IDMantenimiento != 0)
          {
             loading = false;
             progressDialog.dismiss();
             cambios = true;
             getMantenimiento(resultado.IDMantenimiento);
          }
...
...
    
answered by 13.04.2018 в 17:42