Last change using HttpClient, I keep reading the API :(
authorgumartinm <gu.martinm@gmail.com>
Wed, 18 Jan 2012 00:46:40 +0000 (01:46 +0100)
committergumartinm <gu.martinm@gmail.com>
Wed, 18 Jan 2012 00:46:40 +0000 (01:46 +0100)
Android/Testing/Test3/src/de/android/test3/NextActivity.java
Android/Testing/Test3/src/de/android/test3/Test3Activity.java

index bebe5e6..04c7d8d 100644 (file)
@@ -192,39 +192,41 @@ public class NextActivity extends Activity {
           public StringBuilder sortResponse(HttpResponse httpResponse) throws UnsupportedEncodingException, IllegalStateException, IOException {
                   StringBuilder builder = null;
                   
-                  switch (httpResponse.getStatusLine().getStatusCode()) {
-                  case HttpStatus.SC_OK:
-                               //OK
-                               HttpEntity entity = httpResponse.getEntity();
-                               if (entity != null) {
-                                       //outside try/catch block. 
-                                       //In case of exception it is thrown, otherwise instream will not be null and we get into the try/catch block.
-                                       InputStreamReader instream = new InputStreamReader(entity.getContent(), entity.getContentEncoding().getValue());
-                                       try {
-                                               BufferedReader reader = new BufferedReader(instream);                           
-                                               builder = new StringBuilder();
-                                               String currentLine = null;
-                                               currentLine = reader.readLine();
-                                               while (currentLine != null) {
-                                                       builder.append(currentLine).append("\n");
-                                                       currentLine = reader.readLine();
-                                               }
-                                       } finally {
-                                               //instream will never be null in case of reaching this code, cause it was initialized outside try/catch block.
-                                               //In case of exception here, it is thrown to the superior layer.
-                                               instream.close();       
-                                       }                               
-                               }
-                               break;                          
-                  case HttpStatus.SC_UNAUTHORIZED:
-                               //ERROR IN USERNAME OR PASSWORD
-                               break;                          
-                  case HttpStatus.SC_BAD_REQUEST:
-                               //WHAT THE HECK ARE YOU DOING?
-                               break;                          
-                  default:
-                               Log.e(TAG, "Error while retrieving the HTTP status line.");
-                               break;  
+                  if (httpResponse != null) {
+                          switch (httpResponse.getStatusLine().getStatusCode()) {
+                          case HttpStatus.SC_OK:
+                                  //OK
+                                  HttpEntity entity = httpResponse.getEntity();
+                                  if (entity != null) {
+                                          //outside try/catch block. 
+                                          //In case of exception it is thrown, otherwise instream will not be null and we get into the try/catch block.
+                                          InputStreamReader instream = new InputStreamReader(entity.getContent(), entity.getContentEncoding().getValue());
+                                          try {
+                                                  BufferedReader reader = new BufferedReader(instream);                                
+                                                  builder = new StringBuilder();
+                                                  String currentLine = null;
+                                                  currentLine = reader.readLine();
+                                                  while (currentLine != null) {
+                                                          builder.append(currentLine).append("\n");
+                                                          currentLine = reader.readLine();
+                                                  }
+                                          } finally {
+                                                  //instream will never be null in case of reaching this code, cause it was initialized outside try/catch block.
+                                                  //In case of exception here, it is thrown to the superior layer.
+                                                  instream.close();    
+                                          }                            
+                                  }
+                                  break;                               
+                          case HttpStatus.SC_UNAUTHORIZED:
+                                  //ERROR IN USERNAME OR PASSWORD
+                                  break;                               
+                          case HttpStatus.SC_BAD_REQUEST:
+                                  //WHAT THE HECK ARE YOU DOING?
+                                  break;                               
+                          default:
+                                  Log.e(TAG, "Error while retrieving the HTTP status line.");
+                                  break;       
+                          }   
                   }
                   
                   return builder;
index 046a62e..8f2ffb1 100644 (file)
@@ -108,6 +108,9 @@ public class Test3Activity extends Activity {
                                break;
             }          
         } 
+        else {
+               Log.e(TAG, "No response? This should never have happened.");
+        }
     }
     
     public void onClickCancel(View v) {