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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:26:32+00:00 2026-06-06T21:26:32+00:00

I am trying to create and populate an array of objects with information returned

  • 0

I am trying to create and populate an array of objects with information returned from a database query. I can’t seem to get this working properly with my code below.

Any help is appreciated. Thanks in advance.

Module Object:

public class Module {
public String moduleEnglishTitle;
public String moduleJapaneseTitle;
public String moduleCompletionRate;
public int moduleRating;
public Module() {
    super();
}

public Module(String moduleEnglishTitle, String moduleJapaneseTitle, String moduleCompletionRate, int moduleRating) {
    super();
    this.moduleEnglishTitle = moduleEnglishTitle;
    this.moduleJapaneseTitle = moduleJapaneseTitle;
    this.moduleCompletionRate = moduleCompletionRate;
    this.moduleRating = moduleRating;
}

}

These four variables of the object are to be populated from database, into a Module object array in the activity where the data is to be used. This data is then populated into a ListView using a custom ArrayAdapter. The ArrayAdapter, Listview, and Module object all work well together if I manually create the list using this:

Module module_data[] = new Module[] {
            new Module("hello","hello","hello", 3),
            new Module("hello","hello","hello", 2)
    };

However, I don’t want to populate it this way, I want to use data from a database using this cursor:

public Cursor getModuleList() {
    Cursor mCursor = myDataBase.rawQuery("SELECT mod, engtitle, japtitle FROM master WHERE type='module'", null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

I have this code so far, but it’s not working:

    Module module_data[] = new Module[moduleInfo.getCount()];
    int i = 0;
    while(moduleInfo.isAfterLast()) {

        module_data[i].moduleJapaneseTitle = moduleInfo.getString(1);
        module_data[i].moduleEnglishTitle = moduleInfo.getString(2);
        module_data[i].moduleCompletionRate = "済み: " + moduleStats.getString(7);
        module_data[i].moduleRating = moduleStats.getInt(4);

        moduleInfo.moveToNext();
        moduleStats.moveToNext();
        i++;
    }

……………..

06-22 20:42:27.045: E/AndroidRuntime(440): FATAL EXCEPTION: main
06-22 20:42:27.045: E/AndroidRuntime(440): java.lang.RuntimeException: Unable to start activity ComponentInfo{jp.atomicideas.ne/jp.atomicideas.ne.Story2}: java.lang.NullPointerException
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.app.ActivityThread.access$1500(ActivityThread.java:121)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.os.Looper.loop(Looper.java:130)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.app.ActivityThread.main(ActivityThread.java:3701)
06-22 20:42:27.045: E/AndroidRuntime(440):  at java.lang.reflect.Method.invokeNative(Native Method)
06-22 20:42:27.045: E/AndroidRuntime(440):  at java.lang.reflect.Method.invoke(Method.java:507)
06-22 20:42:27.045: E/AndroidRuntime(440):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
06-22 20:42:27.045: E/AndroidRuntime(440):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
06-22 20:42:27.045: E/AndroidRuntime(440):  at dalvik.system.NativeStart.main(Native Method)
06-22 20:42:27.045: E/AndroidRuntime(440): Caused by: java.lang.NullPointerException
06-22 20:42:27.045: E/AndroidRuntime(440):  at jp.atomicideas.ne.Story2.onCreate(Story2.java:59)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-22 20:42:27.045: E/AndroidRuntime(440):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
06-22 20:42:27.045: E/AndroidRuntime(440):  ... 11 more
  • 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-06T21:26:35+00:00Added an answer on June 6, 2026 at 9:26 pm

    I was able to solve it this way:

        Module module_data[] = new Module[moduleInfo.getCount()];
        int i;
        for(i=0; i<7; i++) {
            module_data[i] = new Module(moduleInfo.getString(1), moduleInfo.getString(2),  "済み: " + moduleStats.getString(7), moduleStats.getInt(4));
            moduleInfo.moveToNext();
            moduleStats.movetoNext();
        }
    

    The problem was, that I was incorrectly creating and using the Module objects through its constructor.

    Thanks everyone for your help!

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

Sidebar

Related Questions

I'm trying to populate a JTree from an array of Objects where A's ObjName
I'm trying to create a drop down list that populates from a database. I
I'm trying to populate a JSP dropdown from a database table. Here's the code
I am trying to populate a UITableView with data from json result. I can
I am trying to create a page where users can edit information. I can
I am having a hard time trying to create and populate on the fly
I'm trying to pre-populate create defect popup and I'm not clear on what key/values
Im trying to create an ajax (post) event that will populate a table in
I am trying to populate a select list with time. I want to create
I'm trying to populate an android ListView with data from DB. I've Created a

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.