开发者

android insert row

whit my Activity I display a form like this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/textView1" android:layout_height="wrap_content"
    android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="@string/add_series" android:layout_gravity="center_horizontal"></TextView>
<EditText android:layout_height="wrap_content"
    android:layout_width="match_parent" android:id="@+id/series_name">
    <requestFocus></requestFocus>
</EditText>
<Button android:layout_height="wrap_content" android:id="@+id/button_save"
    android:layout_width="match_parent" android:text="@string/save"></Button>
</LinearLayout>

I have also a method to get this value.

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.add_series);

    final wecDatabasesManager databaseHelper = new wecDatabasesManager(this);

    final Button button_save = (Button) findViewById(R.id.button_save);
    button_save.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            final EditText series_name = (EditText) findViewById(R.id.series_name);  
            String name = series_name.getText().toString();

            databaseHelper.addSeries(null, name, 2);
        }
    });
}

In my DatabasesManager class i have this method.

public void addSeries(SQLiteDatabase db, String name, int publisher_id)
{
    ContentValues v = new ContentValues();
    v.put(wecSeriesTable.NAME, name);
    v.put(wecSeriesTable.PUBLISHER_ID, publisher_id);
    db.insert(wecSeriesTable.TABLE_NAME, null, v);
}

But when i try to save a form value i have this error:

09-13 22:16:57.751: WARN/dalvikvm(2811): threadid=1: thread exiting with uncaught exception (group=0x40015560)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811): FATAL EXCEPTION: main
09-13 22:16:57.761: ERROR/AndroidRuntime(2811): java.lang.NullPointerException
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at zepod.whatelsecomics.databases.wecDatabasesManager.addSeries(wecDatabasesManager.java:102)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at zepod.whatelsecomics.wecSeriesAddActivity$1.onClick(wecSeriesAddActivity.java:25)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at android.view.View.performClick(View.java:2485)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at android.view.View$PerformClick.run(View.java:9080)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at android.os.Handler.handleCallback(Handler.java:587)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at android.os.Looper.loop(Looper.java:123)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at android.app.ActivityThread.main(ActivityThread.java:3647)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at java.lang.reflect.Method.invokeNative(Native Method)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at java.lang.reflect.Method.invoke(Method.java:507)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at dalvik.system.NativeStart.main(Native Method)
09-13 22:16:57.781: WARN/ActivityManager(68):   Force finishing activity zepod.whatelsecomics/.wecSeriesAdd开发者_如何学运维Activity
09-13 22:16:58.321: WARN/ActivityManager(68): Activity pause timeout for HistoryRecord{4076bc68 zepod.whatelsecomics/.wecSeriesAddActivity}

Why? Can someone help me?

I have just update the code.


This is the important information from your StackTrace:

09-13 22:16:57.761: ERROR/AndroidRuntime(2811): java.lang.NullPointerException

09-13 22:16:57.761: ERROR/AndroidRuntime(2811):     at zepod.whatelsecomics.databases.wecDatabasesManager.addSeries(wecDatabasesManager.java:102)

Whatever object(s) your accessing at line 102 in the addSeries method of wecDatabasesManager could potentially be null. Post the addSeries method code if you are unable to quickly figure this one out

EDIT

You're passing a null to addSeries where it's expecting an instance of SqliteDatabase

databaseHelper.addSeries(null, name, 2);

and then:

public void addSeries(SQLiteDatabase db, String name, int publisher_id)
{
    ...
    db.insert(wecSeriesTable.TABLE_NAME, null, v);
}

db is null

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜