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

  • Home
  • SEARCH
  • 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 8950237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:24:35+00:00 2026-06-15T13:24:35+00:00

I got following error. java.lang.NullPointerException: lock == null while get json file from server.I

  • 0

I got following error. java.lang.NullPointerException: lock == null while get json file from server.I googled but cant find any solution for this.

My Code:

try {
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);

            Log.i("clock", httpPost.getURI().toString());
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();           

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            Log.i("Buffer", "1");
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
            Log.i("Buffer", "2");
            StringBuilder sb = new StringBuilder();
            Log.i("Buffer", "3");
            String line = null;
            Log.i("Buffer", "4");
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            Log.i("Buffer", "5");
            json = sb.toString();
            Log.i("Buffer", "6->"+json);
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result-> " + e.toString());
        }

Logcat:

enter image description here

  • 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-06-15T13:24:36+00:00Added an answer on June 15, 2026 at 1:24 pm

    You should always check the instance/ java object is not null before using it anytime.

    eg.

    if( httpResponse != null){
        //todo your work here with "httpResponse "
    }
    

    and

    if(is !=null){
       //todo your work here with "is"
    }
    

    Here is the code example if I would communicate with server

    // this method takes URL as input and returns JSON data 
    //parent class name is "NewWebHelper.java"
    
    public String getResult(String url) {
    
            Log.v(TAG, "Final Requsting URL is : :"+url);
    
            String line = "";
            String responseJsonData = null;
    
            try {
                StringBuilder sb = new StringBuilder();
                String x = "";
                URL httpurl = new URL(url);
                URLConnection  tc= httpurl.openConnection();   
    
                BufferedReader in = new BufferedReader(
                                  new InputStreamReader(tc.getInputStream()));
    
                if(in !=null){
                    while ((line = in.readLine()) != null) {
                    sb.append(line + "\n");
                    x = sb.toString();
                }
                responseJsonData = new String(x);
    
                }
            }
            catch (UnknownHostException uh){            
                Log.v("NewWebHelper", "Unknown host :");
                uh.printStackTrace();
            }
           catch (FileNotFoundException e) {
               Log.v("NewWebHelper", "FileNotFoundException :");
                e.printStackTrace();
             }
            catch (IOException e) {
                Log.v("NewWebHelper", "IOException :");
                e.printStackTrace();
            }
          catch (Exception e) {
              Log.v("NewWebHelper", "Exception :");
                e.printStackTrace();
            }
            return responseJsonData;
        }
    

    Let me know if you have any trouble regrading this.

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

Sidebar

Related Questions

I've got the following java code, which is giving the error below: import java.io.File;
I got following error message: main.xml: java.lang.UnsupportedOperationException Stacktrace says: java.lang.UnsupportedOperationException at android.graphics.Paint_Delegate.nativeGetStringBounds(Paint_Delegate.java:897) at android.graphics.Paint.nativeGetStringBounds(Paint.java)
I got the following error while running my perl script with the negative lookaround
I got the following error while trying to alter a column's data type and
On a server running a Qt application I got the following error, as soon
When I run the code below I get the following error. C:\Documents and Settings\BOS\Desktop\test>java
I am getting the java.lang.NullPointerException on createTabContent for the following code. There are two
While installing my project using the Controller, I got the following error. Starting transmission...
I got following error when serialize (java.util)Date field available in Object. My GWT version
I recently migrate from glassfish 3.1.1 to 3.1.2 and I got the following error

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.