Sqlitedatabase db error = this.getWritableDatabase();

Asked

Viewed 47 times

-1

public ArrayList<String> addMigracaoCadIndividual(String QUERY){
    SQLiteDatabase db = this.getWritableDatabase();
    return null;
}

java.lang.Nullpointerexception at android.content.Contextwrapper.openOrCreateDatabase(Contextwrapper.java:285) at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(Sqliteopenhelper.java:224) at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(Sqliteopenhelper.java:164) at br.com.itconect.sisam.Bancodandos.addMigracaoCadIndividual(Bancodandos.java:565) at br.com.itconect.sisam.Return servicerResposta(Return servicer.java:13) at br.com.itconect.sisam.Sendingshp.onPostExecute(Sendingshp.java:70) at br.com.itconect.sisam.Sendingshp.onPostExecute(Sendingshp.java:14) at android.os.Asynctask.Finish(Asynctask.java:632) at android.os.Asynctask.access$600(Asynctask.java:177) at android.os.Asynctask$Internalhandler.handleMessage(Asynctask.java:645) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.Activitythread.main(Activitythread.java:5299) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:836) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:652) at Dalvik.system.Nativestart.main(Native Method)

  • whenever I run addMigracaoCadIndividual(s) it gives these error msg

1 answer

1

Of course, you’re returning null. The part of the code that calls addMigracaoCadIndividual(s) must be waiting for something that isn’t null (one ArrayList of Strings, in the case).

Try it like this:

public ArrayList<String> addMigracaoCadIndividual(String QUERY){
    SQLiteDatabase db = this.getWritableDatabase();
    ArrayList<String> resultado = new ArrayList<>();
    // Pegue Strings do banco e coloque na ArrayList aqui.
    // Pesquise por exemplos de SQLite para Android no Google.
    resultado.add("Este é só um exemplo");
    return resultado;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.