java.lang.NullPointerException: Attempt to invoke interface method 'java.io.InputStream org.apache.http.HttpEntity.getContent()' on a null object reference

Appcelerator JIRA | Wilson Luu | 11 months ago
  1. 0

    *Details:* Updating a record with Arrow Android SDK throws {{java.lang.NullPointerException}} in the {{onError}} callback. *Notes:* * To workaround this issue, you will need to replace lines 115 - 122 in {{API.java}} with the following: {code} JSONObject json = null; if(entity != null) { InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); StringBuilder builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line); } if(builder.length() != 0) { json = new JSONObject(builder.toString()); } } {code} * The workaround above incorporates the workaround from API-1196. *Steps to reproduce:* # Download and unzip MonkeyArr.zip; this is a *Android Studio* project # Open the project in Android Studio # Next, create an Arrow project and run the Arrow project locally # In the Android project, open {{MainActivity.java}} and change the following: ## Replace the API key in {{MonkeySdk.setAuthorization("71YFaz201s55+Mmvzh5G62sqo3tUwwbS")}}. ## If you are planning to launch against the stock emulator, replace {{10.0.3.2}} with {{10.0.2.2}}; otherwise, leave as-is. # Launch Android app to emualtor or Genymotion emulator # Press the {{Test}} button *Actual:* {{java.lang.NullPointerException}} is thrown to the {{onError}} callback: {code} 02-10 19:31:16.350 24744-24926/com.appc.monkeyarr I/monkeyarr: #1 CREATE and READ test. 02-10 19:31:16.350 24744-24926/com.appc.monkeyarr I/monkeyarr: #Finished test #1. 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr I/monkeyarr: onError 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.io.InputStream org.apache.http.HttpEntity.getContent()' on a null object reference 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at com.monkeysdk.API.execute(API.java:115) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at com.monkeysdk.Testuser$9.doInBackground(Testuser.java:430) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at com.monkeysdk.Testuser$9.doInBackground(Testuser.java:421) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.lang.Thread.run(Thread.java:818) {code} *Expected:* {{java.lang.NullPointerException}} should not be thrown when updating a record.

    Appcelerator JIRA | 11 months ago | Wilson Luu
    java.lang.NullPointerException: Attempt to invoke interface method 'java.io.InputStream org.apache.http.HttpEntity.getContent()' on a null object reference
  2. 0

    *Details:* Updating a record with Arrow Android SDK throws {{java.lang.NullPointerException}} in the {{onError}} callback. *Notes:* * To workaround this issue, you will need to replace lines 115 - 122 in {{API.java}} with the following: {code} JSONObject json = null; if(entity != null) { InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); StringBuilder builder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { builder.append(line); } if(builder.length() != 0) { json = new JSONObject(builder.toString()); } } {code} * The workaround above incorporates the workaround from API-1196. *Steps to reproduce:* # Download and unzip MonkeyArr.zip; this is a *Android Studio* project # Open the project in Android Studio # Next, create an Arrow project and run the Arrow project locally # In the Android project, open {{MainActivity.java}} and change the following: ## Replace the API key in {{MonkeySdk.setAuthorization("71YFaz201s55+Mmvzh5G62sqo3tUwwbS")}}. ## If you are planning to launch against the stock emulator, replace {{10.0.3.2}} with {{10.0.2.2}}; otherwise, leave as-is. # Launch Android app to emualtor or Genymotion emulator # Press the {{Test}} button *Actual:* {{java.lang.NullPointerException}} is thrown to the {{onError}} callback: {code} 02-10 19:31:16.350 24744-24926/com.appc.monkeyarr I/monkeyarr: #1 CREATE and READ test. 02-10 19:31:16.350 24744-24926/com.appc.monkeyarr I/monkeyarr: #Finished test #1. 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr I/monkeyarr: onError 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'java.io.InputStream org.apache.http.HttpEntity.getContent()' on a null object reference 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at com.monkeysdk.API.execute(API.java:115) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at com.monkeysdk.Testuser$9.doInBackground(Testuser.java:430) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at com.monkeysdk.Testuser$9.doInBackground(Testuser.java:421) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 02-10 19:31:16.610 24744-24927/com.appc.monkeyarr W/System.err: at java.lang.Thread.run(Thread.java:818) {code} *Expected:* {{java.lang.NullPointerException}} should not be thrown when updating a record.

    Appcelerator JIRA | 11 months ago | Wilson Luu
    java.lang.NullPointerException: Attempt to invoke interface method 'java.io.InputStream org.apache.http.HttpEntity.getContent()' on a null object reference
  3. 0
    Initialize the variable before calling a method on it.
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0
    Use 'dialog' to access views from custom_layout layout.
  6. 0
    The resource was accessed after it was dismissed.

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      Attempt to invoke interface method 'java.io.InputStream org.apache.http.HttpEntity.getContent()' on a null object reference

      at com.monkeysdk.API.execute()
    2. com.monkeysdk
      Testuser$9.doInBackground
      1. com.monkeysdk.API.execute(API.java:115)
      2. com.monkeysdk.Testuser$9.doInBackground(Testuser.java:430)
      3. com.monkeysdk.Testuser$9.doInBackground(Testuser.java:421)
      3 frames
    3. Android Platform
      AsyncTask$2.call
      1. android.os.AsyncTask$2.call(AsyncTask.java:288)
      1 frame
    4. Java RT
      FutureTask.run
      1. java.util.concurrent.FutureTask.run(FutureTask.java:237)
      1 frame
    5. Android Platform
      AsyncTask$SerialExecutor$1.run
      1. android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
      1 frame
    6. Java RT
      Thread.run
      1. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
      2. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
      3. java.lang.Thread.run(Thread.java:818)
      3 frames