Populate an Array of Objects Using a Database
<p>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.</p>

<p>Any help is appreciated. Thanks in advance.</p>

<p>Module Object:</p>

<pre><code>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;
}
</code></pre>

<p>}</p>

<p>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:</p>

<pre><code>Module module_data[] = new Module[] {
            new Module("hello","hello","hello", 3),
            new Module("hello","hello","hello", 2)
    };
</code></pre>

<p>However, I don't want to populate it this way, I want to use data from a database using this cursor:</p>

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

<p>I have this code so far, but it's not working:</p>

<pre><code>    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++;
    }
</code></pre>

<p>.................</p>

<pre><code>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
</code></pre>
