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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:54:32+00:00 2026-06-15T10:54:32+00:00

I’m calling a web service which gets the data from the database and outputs

  • 0

I’m calling a web service which gets the data from the database and outputs the following JSON :

{"eventId":"1","eventTitle":"opening ceremony","eventCategory":"store","eventSubCategory":"clothing","eventDescription":"This is an event description of some kid for the first event","eventDate":"13/05/2012","eventTime":"14:52","eventAddress":"49 somerset road","eventCity":"southsea","eventCountry":"UK","eventWebsite":"www.nxtldn.com","eventEmail":"lg@nxtldn.com","eventPhone":"07757491567","eventKeywords":"clothes, street, wear, heart, love"},{"eventId":"2","eventTitle":"cupcakes","eventCategory":"Store","eventSubCategory":"food","eventDescription":"This is an event description of some kid for the second event","eventDate":"17/05/2012","eventTime":"11:22","eventAddress":"12 cleveleys road","eventCity":"london","eventCountry":"UK","eventWebsite":"www.ashshort.com","eventEmail":"ashshort@short.com","eventPhone":"0778514562","eventKeywords":"cupcakes, store, london, hipster"}]

which I append (I have tested to see if the JSON is valid using http://jsonlint.com/):

{"Events":[{"eventId":"1","eventTitle":"opening ceremony","eventCategory":"store","eventSubCategory":"clothing","eventDescription":"This is an event description of some kid for the first event","eventDate":"13/05/2012","eventTime":"14:52","eventAddress":"49 somerset road","eventCity":"southsea","eventCountry":"UK","eventWebsite":"www.nxtldn.com","eventEmail":"lg@nxtldn.com","eventPhone":"07757491567","eventKeywords":"clothes, street, wear, heart, love"},{"eventId":"2","eventTitle":"cupcakes","eventCategory":"Store","eventSubCategory":"food","eventDescription":"This is an event description of some kid for the second event","eventDate":"17/05/2012","eventTime":"11:22","eventAddress":"12 cleveleys road","eventCity":"london","eventCountry":"UK","eventWebsite":"www.ashshort.com","eventEmail":"ashshort@short.com","eventPhone":"0778514562","eventKeywords":"cupcakes, store, london, hipster"}]}

I’m calling it using an AsyncTask

public class EventSync extends AsyncTask<String, Integer, EventsList> {

EventsList elist1 = new EventsList();

@Override
protected EventsList doInBackground(String... urls) {
    String tempurl = urls[0];
    String output = "";
    InputStream is = null;
    StringBuilder sb = new StringBuilder();
    EventsList list = new EventsList();
    try
    {
        URL url = new URL(tempurl);
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.connect();
        is = con.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String line = null;

        while((line = reader.readLine()) != null)
        {
            sb.append(line + "\n");
        }

    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        try
        {
            is.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    output = sb.toString();
    String json = "{\"Events\":" + output + "}";
    System.out.println(json);
    Gson gson = new Gson();
// When debugging this is the line I believe it fails on, It points to a bit of memory but the list is empty.
    EventsList jsonlist = gson.fromJson(json, EventsList.class);

    return jsonlist;
}

@Override 
protected void onPostExecute(EventsList list)
{

    System.out.println("in on post");
    for (Event event : list.getEvents())
    {
        System.out.println(event.getEventId());
    }
}}
public class EventsList {

public EventsList(){

}

private List<Event> events;

public List<Event> getEvents()
{
    return events;
}

public void setEventsList(List<Event> events)
{
    this.events = events;
}}

public class Event {

private String eventId;
private String eventTitle;
private String eventCategory;
private String eventSubCategory;
private String eventDescription;
private String eventDate;
private String eventTime;
private String eventAddress;
private String eventCity;
private String eventCountry;
private String eventWebsite;
private String eventEmail;
private String eventPhone;
private String eventKeywords;

public Event()
{

}

// ALL GETS AND SETS

At the moment I’m just trying to test it to see if it will return before I use a custom adapter to populate a listview. But unfortunate I am getting the following error:

11-10 23:37:08.315: E/AndroidRuntime(5592): FATAL EXCEPTION: main
11-10 23:37:08.315: E/AndroidRuntime(5592): java.lang.NullPointerException
11-10 23:37:08.315: E/AndroidRuntime(5592):     at com.nxtldn.trill.EventSync.onPostExecute(EventSync.java:71)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at com.nxtldn.trill.EventSync.onPostExecute(EventSync.java:1)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at android.os.AsyncTask.finish(AsyncTask.java:631)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at android.os.AsyncTask.access$600(AsyncTask.java:177)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at android.os.Looper.loop(Looper.java:137)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at android.app.ActivityThread.main(ActivityThread.java:4745)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at java.lang.reflect.Method.invokeNative(Native Method)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at java.lang.reflect.Method.invoke(Method.java:511)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-10 23:37:08.315: E/AndroidRuntime(5592):     at dalvik.system.NativeStart.main(Native Method)

I new to android so I’m not sure if there is a better way of doing this or what the correct way is.

Is it down the the structure of my JSON why the GSON wont accept and returns null pointers?

Many thanks in advance to anyone that can help 🙂

  • 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-15T10:54:33+00:00Added an answer on June 15, 2026 at 10:54 am

    I found it was due to me adding “/n” to my string builder, creating the new line and chopping off the final } of the json. Thanks everyone

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.