Error SQLiteDatabase db = this.getWritableDatabase (); [closed]

-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 .com.sisam.BancoDandos.addMigracaoCadIndividual (BancoDandos.java:565)           at server.servers.servers.servers.servers           at br.com.itconect.sisam.EnvoteDatesPhp.onPostExecute (SendDatesPhp.java:70)           at br.com.itconect.sisam.EnvoteDatesPhp.onPostExecute (SendDatesPhp.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)

    
asked by anonymous 09.04.2018 / 20:48

1 answer

1

Of course, you are returning null . The part of the code that calls addMigracaoCadIndividual(s) must be expecting something other than null (a ArrayList Strings , in this case).

Try 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;
}
    
10.04.2018 / 00:26