views:

272

answers:

1

I am creating an application which tracks the users location using GPS, stores the longitude and latitude in a database using a content provider then output the first long and lat to a mapview.

I am able to create the cursor using this line of code:

Cursor c = getContentResolver().query(GPSContentProvider.CONTENT_URI,
                                                      null, null, null, null);
startManagingCursor(c);

However, when I make a call to move to the first row in the database or even try to close the cursor using c.close(); I receive a NullPointerException.

Edit: Just to make it clear, I can store the longitude, latitude and time in milli's within the database, the problem is then taking the data out of the database and displyaing this on a map.

Updated code:

public static final String AUTHORITY = "application.android.prototype";
// followed by the CONTENT_URI
public static final Uri CONTENT_URI = Uri.
                    parse("content://" + AUTHORITY + "/gpspoints");

Updated permissions:

<provider android:name="GPSDataContentProvider" android:authorities="application.android.prototype">
</provider>
A: 

Hi,

I decided against using the ContentProvider in the end as my application's database is only going to be used by that single application.

Instead, I created a typical database using SQL and used a similar Cursor function:

SQLiteDatabase db = waypoints.getReadableDatabase(); Cursor cursor = db.query(TABLE_NAME, FROM, null, null, null, null, ORDER_BY); startManagingCursor(cursor); return cursor;

LordSnoutimus