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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:53:25+00:00 2026-05-23T03:53:25+00:00

I want to ask about how to store data retrieved from a cursor object

  • 0

I want to ask about how to store data retrieved from a cursor object in an array. I am unable to do that and getting an null pointer exception because I am not able to initialize the size of the array? Where do I write that code and store all the data retrieved from cursor object in an array. Please I am unable to do that.

My code for retrieving the data from the cursor is below.

if (c != null ) {
    if  (c.moveToFirst()) {
        do {
            firstName = c.getString(c.getColumnIndex("FirstName"));
            int age = c.getInt(c.getColumnIndex("Age"));
            //results.add("Name: " + firstName + ",Age: " + age);
        }while (c.moveToNext());
    } 
}           
  • 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-23T03:53:25+00:00Added an answer on May 23, 2026 at 3:53 am

    The problem is, that you have two values that you want to store. So a normal array will not solve the problem. You can use an ArrayList of a custom class. Or you use the Pair class.

    Try this:

    if (c != null ) {
        ArrayList<Pair<String, String>> list = new ArrayList<Pair<String, String>>();
        if  (c.moveToFirst()) {
            do {
                list.put(new Pair<c.getString(c.getColumnIndex("FirstName"), c.getInt(c.getColumnIndex("Age")>));
                //firstName = c.getString(c.getColumnIndex("FirstName"));
                //int age = c.getInt(c.getColumnIndex("Age"));
                //results.add("Name: " + firstName + ",Age: " + age);
            }while (c.moveToNext());
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI, everyone, I want to ask a question about the iPhone application. I want
I want to ask a question about the objective C on iPhone. I want
I want to ask a question about the iPhone. I am writing a program
I want to ask about the passing parameter in objective C on iPhone simulator.
I want to ask a question about the objective C. I have create a
I just want to ask something about my code. #define LIM 40 main() {
I want to ask a general question about the proper way to handle a
'm developing a 2D game and I want separate the game engine from the
Howdy, I am a programmer that has worked almost exclusively with c++/c#/vbs and am
Possible Duplicate: How can I stay up-to-date on computer (especially software) security? I want

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.