0

I have an android programm which manage a database. It this database, I write the sensor values of my device.

When close the application with the home button, i have a force close error.

Here is my logcat, can you please help me, thank you.

`12-27 10:45:20.827: D/AndroidRuntime(1053): Shutting down VM  
12-27 10:45:20.827: W/dalvikvm(1053): threadid=1: thread exiting with uncaught exception (group=0x40014760)  
12-27 10:45:20.942: E/AndroidRuntime(1053): FATAL EXCEPTION: main  
12-27 10:45:20.942: E/AndroidRuntime(1053): java.lang.NullPointerException  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:283)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:116)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1732)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1605)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at milos.stationdemesure.CapteursBDD.insertValeursCapteur(CapteursBDD.java:69)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at milos.stationdemesure.EssaisCapteurs.onProximityChanged(EssaisCapteurs.java:454)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at milos.stationdemesure.EssaisCapteurs.onSensorChanged(EssaisCapteurs.java:354)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.hardware.SensorManager$ListenerDelegate$1.handleMessage(SensorManager.java:529)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.os.Looper.loop(Looper.java:126)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at android.app.ActivityThread.main(ActivityThread.java:3997)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at java.lang.reflect.Method.invokeNative(Native Method)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at java.lang.reflect.Method.invoke(Method.java:491)
12-27 10:45:20.942: E/AndroidRuntime(1053):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)  
12-27 10:45:20.942: E/AndroidRuntime(1053):     at dalvik.system.NativeStart.main(Native Method)
`
Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
  • Lack of code code doesn't help. I guess that unregistering sensor listener could fix this issue. – LordTwaroog Dec 27 '11 at 10:56
  • You insert null value or some thing is null in your code – sam_k Dec 27 '11 at 10:57
  • if you past the full logcat it should give you a hint to where in your code you are getting the Bull exception pointer. I would guess something in one of the onStop or onDestroy functions of one of your activities. – MikeIsrael Dec 27 '11 at 10:58
  • Uh, my code is tooo big, i have listeners but normaly, i am unregistering all of them at the end. I think I have found the problem, i am closing my DataBase on closing application with nameOfThBase.close(); Which is normal i think. When i have deleted this instruction, all works well. Do yo know why??? – Milos Cuculovic Dec 27 '11 at 11:02
  • http://stackoverflow.com/questions/7999075/ – usethe4ce Feb 20 '12 at 18:58

2 Answers2

1

I feel the issue is either database instance or any other object became null but you are calling some method using that object. Always check for null before using any methods of any object. see the sample example

example

if(database != null){
database.close();
} 
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
0

Looks similar to this issue: SQLiteDatabase close() function causing NullPointerException when multiple threads

You may not need to call database.close()

Community
  • 1
  • 1
parkerfath
  • 1,648
  • 1
  • 12
  • 18