Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException. Unable to read through stream
    text
    copied!<p>I'm trying to make a http request to connect with an application and do authentication procedure.But i'm gettting <strong>NullpointerException</strong> .The connection object is not able to get the stream data.Which is causing a null pointer exception .Here is my code <br/></p> <pre><code>String api="URL of the application"; String query="format=json"; //Necessary Variables String publicKey=publickey; String privateKey=privatekey; String email=uemail; String password=upassword; String algo="HmacSHA1"; //identify Application long time=System.currentTimeMillis() / 1000; SecretKeySpec sks=new SecretKeySpec(privateKey.getBytes(),algo); try { Mac mac=Mac.getInstance(algo); mac.init(sks); String hash=""; byte[] digest=mac.doFinal((query+time).getBytes()); for (byte b : digest) { hash +=String.format("%02x", b); } //Make the request String url=api+"?"+query+"&amp;apikey="+publicKey+"&amp;hash="+hash+"&amp;t="+time; Log.d("URL", "url: "+url); try { HttpsURLConnection c=(HttpsURLConnection) new URL(url.trim()).openConnection(); c.setRequestProperty("Authorization","Basic "+DatatypeConverter.printBase64Binary((email+":"+password).getBytes())); InputStream iStream=null; try { ***iStream=c.getInputStream();*** } catch (Exception e) { iStream=c.getErrorStream(); } InputStreamReader iStreamReader=new InputStreamReader(iStream); BufferedReader bReader=new BufferedReader(iStreamReader); String result=""; String line=""; while ((line=bReader.readLine())!=null) { result +=line+"\n"; } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } </code></pre> <p>Here is the Exception.</p> <pre><code>10-17 11:09:38.127: E/AndroidRuntime(864): FATAL EXCEPTION: main 10-17 11:09:38.127: E/AndroidRuntime(864): java.lang.NullPointerException 10-17 11:09:38.127: E/AndroidRuntime(864): at libcore.net.http.HttpEngine.writeRequestHeaders(HttpEngine.java:646) 10-17 11:09:38.127: E/AndroidRuntime(864): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:800) 10-17 11:09:38.127: E/AndroidRuntime(864): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274) 10-17 11:09:38.127: E/AndroidRuntime(864): at libcore.net.http.HttpURLConnectionImpl.getErrorStream(HttpURLConnectionImpl.java:100) 10-17 11:09:38.127: E/AndroidRuntime(864): at libcore.net.http.HttpsURLConnectionImpl.getErrorStream(HttpsURLConnectionImpl.java:124) 10-17 11:09:38.127: E/AndroidRuntime(864): at com.arc.distimoapp.LoginScreen.loginDistimo(LoginScreen.java:113) 10-17 11:09:38.127: E/AndroidRuntime(864): at com.arc.distimoapp.LoginScreen$1.onClick(LoginScreen.java:62) 10-17 11:09:38.127: E/AndroidRuntime(864): at android.view.View.performClick(View.java:4084) 10-17 11:09:38.127: E/AndroidRuntime(864): at android.view.View$PerformClick.run(View.java:16966) 10-17 11:09:38.127: E/AndroidRuntime(864): at android.os.Handler.handleCallback(Handler.java:615) 10-17 11:09:38.127: E/AndroidRuntime(864): at android.os.Handler.dispatchMessage(Handler.java:92) 10-17 11:09:38.127: E/AndroidRuntime(864): at android.os.Looper.loop(Looper.java:137) 10-17 11:09:38.127: E/AndroidRuntime(864): at android.app.ActivityThread.main(ActivityThread.java:4745) 10-17 11:09:38.127: E/AndroidRuntime(864): at java.lang.reflect.Method.invokeNative(Native Method) 10-17 11:09:38.127: E/AndroidRuntime(864): at java.lang.reflect.Method.invoke(Method.java:511) 10-17 11:09:38.127: E/AndroidRuntime(864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 10-17 11:09:38.127: E/AndroidRuntime(864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-17 11:09:38.127: E/AndroidRuntime(864): at dalvik.system.NativeStart.main(Native Method) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload