Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:09:43+00:00 2026-05-28T17:09:43+00:00

I have sometimes error but can’t understand why : Code : public void newConnect()

  • 0

I have sometimes error but can’t understand why :

Code :

public void newConnect()
        { try {
          urlka = new URL(myUrl);

        } catch (MalformedURLException e) {

            e.printStackTrace();
        }
          HttpURLConnection conn = null;
        try {
            conn = (HttpURLConnection) urlka.openConnection();
            conn.connect();
            Log.v("Responcse code","Response code " +conn.getResponseCode());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
           try {
             try {
                in = new BufferedInputStream(conn.getInputStream());

             } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
          result =  readStream(in); /// line 1198

           }
            finally {
             conn.disconnect();
           }

readStrem ()

private String readStream(InputStream is)
        {
                    try 
                    {
                      ByteArrayOutputStream bo = new ByteArrayOutputStream();
                     int i = is.read(); /// **error was here** line 1247


                      while(i != -1) 
                      {
                        bo.write(i);

                        i = is.read();
                      }

                      return bo.toString();
                    } catch (IOException e) 
                    {
                      return ""+e;
                    }
        }
            }

Logcat:

java.lang.RuntimeException: An error occured while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:200)
    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
    at java.lang.Thread.run(Thread.java:1096)
Caused by: java.lang.NullPointerException
    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$LocalCloseInputStream.read(HttpURLConnectionImpl.java:167)
    at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:157)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:243)
    at myApp.activity.com.myApp.readStream(myApp.java:1247)
    at myApp.activity.com.myApp.newConnect(myApp.java:1198)
    at myApp.activity.com.myApp$newRun.doInBackground(myApp.java:424)
    at myApp.activity.com.myApp$newRun.doInBackground(myApp.java:1)
    at android.os.AsyncTask$2.call(AsyncTask.java:185)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

This error is sometimes. But it’s error 🙁 Can any help me solve this problem ?
I can’t undestand why this error.

Regards, Peter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:09:44+00:00Added an answer on May 28, 2026 at 5:09 pm

    Some time there may be problem, with connectivity due to which in = new BufferedInputStream(conn.getInputStream()); throws error, and input stream remain null. YOu need to handle null case also to get rid of the issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i found a code but sometimes have error : StringBuilder strHeaders = new StringBuilder();
it's realy rare error for me but.. It's error. Can't understand why. error just
While looking at online code samples, I have sometimes come across an assignment of
Sometimes I have a true colored image, by using dithering algorithm, I can reduce
I have an application were users can upload pics. The code below allow only
i have my application that sometimes will freeze, without any error in console. I
Sometimes my scripts produce an error, mostly a Warning . I have sometimes an
I have successful FB Credits integration, which receives many requests per day. But sometimes
we have a bunch of reports (RDL) on SSRS built using officewriter. Sometimes errors
When printing a report, the user sometime have the following error: CrystalDecisions.CrystalReports.Engine.LogOnException: Error in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.