How can I reference cursor item in a for loop?
<p>I'm attempting to loop through database values creating tabs.  I have setup a method called createTab which accepts a Long value and a String value.  It's working with static data, but I'm struggling to understand how to loop through SQLite database records.</p>

<p>Here is my failed attempt (replace [lessthan] with less than symbol):</p>

<pre><code>
for (int i = 0; i [lessthan] mCursor.getCount(); i++)
{
 createTab(
  mCursor.getLong(mCursor.getColumnIndexOrThrow("_id")),
  mCursor.getString(mCursor.getColumnIndexOrThrow("category")));
}
</code></pre>

<p>You probably don't need the LogCat to know what I did wrong in the code above, but just in case...</p>

<pre>
08-27 21:28:18.268: ERROR/AndroidRuntime(232): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:172)
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:99)
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     at com.toBuy.Main.createTabs(Main.java:51)
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     at com.toBuy.Main.onCreate(Main.java:38)
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
08-27 21:28:18.268: ERROR/AndroidRuntime(232):     ... 11 more
08-27 21:28:18.278: INFO/Process(54): Sending signal. PID: 232 SIG: 3
08-27 21:28:18.278: INFO/dalvikvm(232): threadid=7: reacting to signal 3
08-27 21:28:18.338: INFO/dalvikvm(232): Wrote stack trace to '/data/anr/traces.txt'
08-27 21:28:18.508: INFO/ARMAssembler(54): generated scanline__00000077:03515104_00000000_00000000 [ 27 ipp] (41 ins) at [0x285a68:0x285b0c] in 713498 ns
08-27 21:28:18.518: INFO/ARMAssembler(54): generated scanline__00000077:03515104_00001001_00000000 [ 64 ipp] (84 ins) at [0x285b10:0x285c60] in 1897448 ns
08-27 21:28:28.086: WARN/ActivityManager(54): Launch timeout has expired, giving up wake lock!
08-27 21:28:28.097: WARN/ActivityManager(54): Activity idle timeout for HistoryRecord{4390bf70 com.toBuy/.Main}
</pre>

<p>Thank you for your help.</p>
