atedatabase提供nullpointerexceptio

atedatabase提供nullpointerexceptio

本文介绍了openorcreatedatabase提供nullpointerexception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前在使用的Android应用中使用过数据库所以通常我打开()数据库查询结束后,我再次关闭()

i used databases before in the android app i am working onso usualy i open() the databasewhen my query is finished i close() it again

在我对数据库类的最新更改中,我得到了一个错误给出以下痕迹

with my latest change to my database class i get an errorgiving following traces

  02-23 14:27:55.261: I/webserver do in background(23728): bezoek = [Ljava.lang.String;@40e324a0
02-23 14:27:55.261: D/AndroidRuntime(23728): Shutting down VM
02-23 14:27:55.261: W/dalvikvm(23728): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
02-23 14:27:55.311: E/AndroidRuntime(23728): FATAL EXCEPTION: main
02-23 14:27:55.311: E/AndroidRuntime(23728): java.lang.NullPointerException
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:229)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.example.deceunincktechniekers.ABezoeAdapter$dbhulp.<init>(ABezoeAdapter.java:60)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.example.deceunincktechniekers.ABezoeAdapter.open(ABezoeAdapter.java:87)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.example.deceunincktechniekers.AWebServAdapter.synchroniseren(AWebServAdapter.java:186)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.example.deceunincktechniekers.bezoekrapporten.handlescan(bezoekrapporten.java:146)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.example.deceunincktechniekers.bezoekrapporten$1.onEditorAction(bezoekrapporten.java:68)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.widget.TextView.doKeyDown(TextView.java:5314)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.widget.TextView.onKeyDown(TextView.java:5204)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.KeyEvent.dispatch(KeyEvent.java:2609)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.View.dispatchKeyEvent(View.java:7205)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.widget.ScrollView.dispatchKeyEvent(ScrollView.java:353)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1920)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1395)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.app.Activity.dispatchKeyEvent(Activity.java:2370)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1847)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3701)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3651)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2818)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.os.Looper.loop(Looper.java:137)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at android.app.ActivityThread.main(ActivityThread.java:5041)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at java.lang.reflect.Method.invokeNative(Native Method)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at java.lang.reflect.Method.invoke(Method.java:511)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-23 14:27:55.311: E/AndroidRuntime(23728):    at dalvik.system.NativeStart.main(Native Method)

由于我更改了这部分代码,所以发生了此错误

this errors occure since i have changed this part of code

public void gegevensupdaten(String bezoeknummer, String[] data) {
            Log.i("AbezoeAdapter gegevensupdaten", "bezoeknummer= " + bezoeknummer + "gegevens = " + data);
            open();
            ContentValues cv = new ContentValues();

            cv.put(bezoekrapportdatum, data[2]);
            cv.put(herstellingsoort, data[3]);


            Log.i("test","gelukt");


            onzedatabase.update(databasetabel, cv,  bezoekrapportnummer + "=?", new String[] {bezoeknummer});
            sluit();
            return;
        }

在调用函数open()时发生错误但是此功能是开放的,因为它在我到达代码的这一部分之前就一直使用(此时它不会阻塞)

the error occures at the moment of calling the function open()but this function is open as it is always used before i reach this part of code (and at that moment it doesn't block)

我的open()方法如下:

my open() method looks like:

private static class dbhulp extends SQLiteOpenHelper
{

    dbhulp(Context context) {
        super(context, ADbAdapter.databasenaam, null, ADbAdapter.databaseversie);
        getWritableDatabase();
        Log.i("abezoe dbhulp", "dbhulp goed doorbracht");
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        ADbAdapter.onCreate(db);
        Log.i("adbadapter", "oncreate opgeroepen");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        ADbAdapter.onUpgrade(db, oldVersion, newVersion);
        Log.i("adbadapter", "onupgrade opgeroepen");


    }



}
public ABezoeAdapter(Context c){
    onzecontext = c;
}

public ABezoeAdapter open() throws SQLException{
    onzehelper = new dbhulp(onzecontext);
    onzedatabase = onzehelper.getWritableDatabase();
    Log.i("abezoeadapter open", "gelukt");
    return this;
}

public void sluit(){
    onzehelper.close();

}

经过数小时的互联网搜索,我了解到我不是唯一一个遇到此错误的人,但是似乎没人能为我的问题提供很好的解决方案感谢您的提前帮助

hours of searching on the internet learned me that i am not the only one running against this error but nobody seems to provide a good sollution for my problemthanks for your help in advance

我刚刚发现了一个帖子,该帖子可能涉及相同的问题

i just found a post that probably deals about the same problem

但我不明白给出的答案:

but i don't understand the answer given:

有人可以帮助我理解我的失败吗?

can anybody help to understand my failure?

推荐答案

堆栈跟踪显示您传递给 SQLiteOpenHelper Context null .

The stacktrace says the Context you passed to SQLiteOpenHelper was null.

该代码未显示如何初始化 Context 所在的 ABezoeAdapter ,但这是您应寻求解决问题的地方.

The code doesn't show how you initialize your ABezoeAdapter where the Context comes from but that's where you should be looking to solve the problem.

这篇关于openorcreatedatabase提供nullpointerexception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:28