• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps GPS and SQLiteDatabase tied for functionality?

I'm creating an app that requires GPS to gather information and insert this information into a SQLiteDatabase. The app works perfectly fine as coded UNTIL the GPS is turned off. Apparently, when the GPS is turned off, my insert method for the database throws a NullPointerException. I figured it was because the location object was null since there was no actual GPS location. So, I created dummy variables to insert into the database in case the GPS was turned off, but am still getting a NullPointerException when calling db.insert with these dummy variables. I've checked all possible points of failure and know for a fact correct types and values are being sent. Does anyone know if for some strange reason that the SQLiteDatabase is tied to the GPS in any way, shape or form that would cause this to fail?
 
I'm creating an app that requires GPS to gather information and insert this information into a SQLiteDatabase. The app works perfectly fine as coded UNTIL the GPS is turned off. Apparently, when the GPS is turned off, my insert method for the database throws a NullPointerException. I figured it was because the location object was null since there was no actual GPS location. So, I created dummy variables to insert into the database in case the GPS was turned off, but am still getting a NullPointerException when calling db.insert with these dummy variables. I've checked all possible points of failure and know for a fact correct types and values are being sent. Does anyone know if for some strange reason that the SQLiteDatabase is tied to the GPS in any way, shape or form that would cause this to fail?

Why don't you just check the GPS state of the phone and only do the insert method if the GPS is active.
 
Well the problem has officially been fixed. Apparently because the GPS lookup was in the foreground process, it would cause the application to force close upon leaving the Activity. Instead, I moved the GPS lookup and check to a background service and checked there. If the location wasn't null I got the info I needed and announced it back to the first Activity and then used a BroadcastReceiver to get the info. If location was null i announced dummy variables in the Service and posted those instead.
 
Back
Top Bottom