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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:54:48+00:00 2026-06-13T21:54:48+00:00

Hi i am having trouble to get the JSONObject value title and store into

  • 0

Hi i am having trouble to get the JSONObject value title and store into the array.

public class ViewPagerAdapter extends PagerAdapter 
{   
// JSON Node names
     private static final String TAG_CATEGORIESLIST = "categorylist";
     private static final String TAG_TITLE = "title";
     private static final String TAG_URL = "url";
     public static String[] titles;
     public final Context context;
     public int[] scrollPosition;
     JSONArray categories = null; 
     JSONObject json;
     {
         try {
                JSONFunction JSONFunction = new JSONFunction();
               json = JSONFunction.categorylist();
               // Getting Array of Categories
               categories = json.getJSONArray(TAG_CATEGORIESLIST);
                // looping through All Categories
               for(int i = 0; i < categories.length(); i++){
                JSONObject c = categories.getJSONObject(i);
                // Storing each json item in variable
                String title = c.getString(TAG_TITLE);
                String url = c.getString(TAG_URL); 
                titles = new String[] {title}; //only obtain one result
                scrollPosition = new int[titles.length];
            }

            } catch (JSONException e) {
                e.printStackTrace();
            }   
     }
...

My titles only get one value, need some help from u guys.

Addon:

I am using Viewpagerindicator library, the default code to display the title is like tat

private static String[] titles = new String[] { “Page 1”, “Page 2”,
“Page 3”, “Page 4”, “Page 5”};

I am trying to input json data into there.
Thanks.

  • 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-13T21:54:49+00:00Added an answer on June 13, 2026 at 9:54 pm

    you are not incrementing the titles array

    Change this

     titles = new String[] {title};//Because of this your last retrived  value will be stored in titles
    

    to

     titles[i] = title;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble parsing my JSON which i get from javascript. The format
I am having trouble figuring out how to get Facebook insights into from my
I am having trouble to get display result from JSON. Userfunctions.java To get the
I'm having trouble returning a JSON object, instead all I get is an undefined
I am having trouble trying to get a file to be included into a
I'm having trouble trying to get my class working in my node.js file. When
I'm having trouble trying to parse a json array string sent from Django to
I am having trouble to get all rows data from sql. DatabaseHandler.java public HashMap<String,
I'm having trouble trying to get a linebreak included in a Stringbuilder to appear
I am having trouble trying to get iterators for inner sub-containers. Basically imagine this

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.