Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help reading from SQLite database for Android
    primarykey
    data
    text
    <p>I have read through many sites and tutorials and have been unable to solve my problem. I have an application that works until I try to read from my database (it opens it just fine). I know its not the right way to do things but I have two global strings that I pass from my main activity to my DataBaseHelper class (<code>DB_TABLE</code> and <code>spinnerPipeLengthText</code>). When I call the following line of code to retrieve the data from all the columns in a specific row my application crashes.</p> <pre><code>Cursor cursorData = myDataBase.query(CSSTPipeSizingActivity.DB_TABLE, null, CSSTPipeSizingActivity.spinnerPipeLengthText, null, null, null, null, null); </code></pre> <p>Here is my complete <code>getData</code> method:</p> <pre><code>public Cursor getData() { Cursor cursorData = myDataBase.query(CSSTPipeSizingActivity.DB_TABLE, null, CSSTPipeSizingActivity.spinnerPipeLengthText, null, null, null, null, null); if (cursorData != null) cursorData.moveToFirst(); cursorData.moveToFirst(); CSSTPipeSizingActivity.textViewSize15.setText(cursorData.getString(1)); cursorData.moveToNext(); CSSTPipeSizingActivity.textViewSize19.setText(cursorData.getString(1)); cursorData.moveToFirst(); CSSTPipeSizingActivity.textViewSize25.setText(cursorData.getString(1)); cursorData.moveToNext(); CSSTPipeSizingActivity.textViewSize31.setText(cursorData.getString(1)); cursorData.moveToFirst(); CSSTPipeSizingActivity.textViewSize37.setText(cursorData.getString(1)); cursorData.moveToNext(); CSSTPipeSizingActivity.textViewSize46.setText(cursorData.getString(1)); cursorData.moveToNext(); CSSTPipeSizingActivity.textViewSize62.setText(cursorData.getString(1)); cursorData.close(); return cursorData; } // end method getData </code></pre> <p>As you can see from my code, I am trying to take the data and input it straight into text views in the <code>main.xml</code> file. I don't know if this is possible but that will be for me to figure out later. Right now I need to get the data.</p> <p>Here is my logcat:</p> <pre><code>03-12 19:23:33.587: D/AndroidRuntime(20191): Shutting down VM 03-12 19:23:33.587: W/dalvikvm(20191): threadid=1: thread exiting with uncaught exception (group=0x40015560) 03-12 19:23:33.617: E/AndroidRuntime(20191): FATAL EXCEPTION: main 03-12 19:23:33.617: E/AndroidRuntime(20191): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skyesmechanical.CSSTPipeSizing/com.skyesmechanical.CSSTPipeSizing.CSSTPipeSizingActivity}: java.lang.NullPointerException 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.os.Handler.dispatchMessage(Handler.java:99) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.os.Looper.loop(Looper.java:123) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.app.ActivityThread.main(ActivityThread.java:3683) 03-12 19:23:33.617: E/AndroidRuntime(20191): at java.lang.reflect.Method.invokeNative(Native Method) 03-12 19:23:33.617: E/AndroidRuntime(20191): at java.lang.reflect.Method.invoke(Method.java:507) 03-12 19:23:33.617: E/AndroidRuntime(20191): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 03-12 19:23:33.617: E/AndroidRuntime(20191): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 03-12 19:23:33.617: E/AndroidRuntime(20191): at dalvik.system.NativeStart.main(Native Method) 03-12 19:23:33.617: E/AndroidRuntime(20191): Caused by: java.lang.NullPointerException 03-12 19:23:33.617: E/AndroidRuntime(20191): at com.skyesmechanical.CSSTPipeSizing.DataBaseHelper.getData(DataBaseHelper.java:173) 03-12 19:23:33.617: E/AndroidRuntime(20191): at com.skyesmechanical.CSSTPipeSizing.CSSTPipeSizingActivity.onCreate(CSSTPipeSizingActivity.java:105) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 03-12 19:23:33.617: E/AndroidRuntime(20191): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 03-12 19:23:33.617: E/AndroidRuntime(20191): ... 11 more </code></pre> <p>Thanks for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload