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 6884745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:32:50+00:00 2026-05-27T05:32:50+00:00

I am calling a Java servlet from my Java file. The servlet file has

  • 0

I am calling a Java servlet from my Java file. The servlet file has SOP to return a JSON string. Now I wish to use that string in my Java code and then parse it into XML.

My code is as follows:

URL urlS = new URL (servletURL);
URLConnection urlc;
urlc = urlS.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()));

String inputLine;
while ((inputLine = in.readLine()) != null)
    System.out.println("We got JSON Buddy: "+inputLine);
JSONObject js = new JSONObject(inputLine);
System.out.println("We got json object js: "+js.toString());
in.close();

The problem is my SOP for Java code is :

12-02 10:30:12.254: I/System.out(24169): We got JSON Buddy: {"movies": { "total": 19, "movie":[{"cover":"http://content9.flixster.com/movie/11/16/04/11160419_pro.jpg","tile":"A Very Harold & Kumar 3D Christmas","MovieDuration":"(R , 1 hr. 29 min.)","showtime":"                                                                                                                                                                                                                                                                                                                                                                                                                                                                           9:35 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         12:00 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                ","theatre":"Rave Motion Pictures 18 + IMAX","url":"http://www.flixster.com/movie/a-very-harold-and-kumar-christmas"},{"cover":"http://content6.flixster.com/movie/11/16/12/11161272_pro.jpg","tile":"Arthur Christmas 3D","MovieDuration":"(PG , 1 hr. 37 min.)","showtime":"                                                                                                                                                                                                                                                                                                                                                                                                                                                                           12:15 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         3:00 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         5:35 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                ","theatre":"Rave Motion Pictures 18 + IMAX","url":"http://www.flixster.com/movie/arthur-christ
12-02 10:30:12.266: I/System.out(24169): Exception: java.lang.NullPointerException

The issue is I am not getting the complete output in the inputLine, and the other problem is the NullPointerException. I am not able to figure out why this is happening.

  • 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-27T05:32:52+00:00Added an answer on May 27, 2026 at 5:32 am

    You’re loop is doing this:

      while ((inputLine = in.readLine()) != null)
                    System.out.println("We got JSON Buddy: "+inputLine);
    

    For the loop to terminate, inputLine has to be null so when you get here: JSONObject js = new JSONObject(inputLine);
    you will get a null pointer exception.

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

Sidebar

Related Questions

I read that you could call JavaScript code from a Java Applet by calling
By calling the example URL below my Java servlet caches one file at a
I'm trying to use boilerpipe from JRuby. I've seen the guide for calling Java
My Servlet just won't use UTF-8 for JSON responses. MyServlet.java : public class MyServlet
I am calling a vendor's Java API, and on some servers it appears that
I am currently calling the following line of code: java.net.URL connection_url = new java.net.URL(http://<ip
I need this for calling a C function from Java class (JNI) and I
Java 6 API question. Does calling LockSupport.unpark(thread) have a happens-before relationship to the return
I'm using a java.util.concurrent.ExecutorService that I obtained by calling Executors.newSingleThreadExecutor() . This ExecutorService can
I've got a problem where calling grep from inside java gives incorrect results, as

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.