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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:03:55+00:00 2026-06-15T12:03:55+00:00

i’m trying to retrieve text from wikipedia to use on an Android app. I’m

  • 0

i’m trying to retrieve text from wikipedia to use on an Android app. I’m using Java.
The first thing I want to do is to retrieve the sections from an specific article, show them to the user and, when the user clicks on one section, get the section text with another http request.

So, the two requests are these:

http://en.wikipedia.org/w/api.php?format=json&action=parse&page=Valencia_Cathedral&prop=sections

and then this one:

http://en.wikipedia.org/w/api.php?format=json&action=parse&page=Valencia_Cathedral&prop=text&section=1

My question is: What kind of java objects should I create to store the information and then convert it to these classes using .fromJSON()?

Thanks to @NathanZ, I created these two classes:

public class WikiResponseSections {
    String title;
    List<Section> sections;
}

public class Section {
        int toclevel;
        String level;
        String line;
        String number;
        String index;
        String fromtitle;
        int byteoffset;
        String anchor;
}

But, when I convert the HTTP response to these objets by Gson, and try to read the value of the field ‘title’ there’s an error that triggers: JavaNullPointerException.
Here’s my code for the conversion:

InputStream stream = null;
try {
    stream = entity.getContent();
} catch (IllegalStateException e) {
    Log.e("Stream","ERROR illegalstateexception");
} catch (IOException e) {
    Log.e("Stream","ERROR exception");
}
reader = new BufferedReader(new InputStreamReader(stream));
GsonBuilder bldr = new GsonBuilder();
Gson gson = bldr.create();
WikiResponse = gson.fromJson(reader, WikiResponseSections.class);
if (WikiResponse != null){
    Log.i("WikiResponse",WikiResponse.getTitle()); //The error triggers HERE
    publishProgress();
}
else
    Log.i("WikiResponse","NULL");
}

Thanks for your help again

  • 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-15T12:03:58+00:00Added an answer on June 15, 2026 at 12:03 pm

    You can use the Google’s Gson library.
    It works like this:

    InputStream source = ...; // your code to get the Json from a url
    Gson gson = new Gson();
    Reader reader = new InputStreamReader(source);
    MyResponse response = gson.fromJson(reader, MyResponse.class);
    

    Where MyResponse is your object. When you create MyResponse, give your fields the same name and type as the Json’s fields

    MyResponse class can be as follows:

    public class MyResponse{
        String title;
        ArrayList<sections>;
    }
    
    public class sections{
        int toclevel;
        String level;
        String line;
        String number;
        String fromtitle;
        long byteoffset;
        String anchor;
    }
    
    
    
    public class WikiResponseParse{
        Parse parse;
        public class Parse{
            String title, text;
        }
    }
    

    If you can’t use the json fields name because it’s not Java compliant:

    Add the following import:

    import com.google.gson.annotations.SerializedName;
    

    and in your class:

    @SerializedName("*")
    public String star;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload

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.