NullPointerException with cursor

Put your problem here if it does not fit any of the other categories.

NullPointerException with cursor

Postby Lordsnoutimus » Thu Mar 18, 2010 6:22 pm

Hi,

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  Cursor c = getContentResolver().query(GPSContentProvider.CONTENT_URI, null, null, null, null); startManagingCursor(c);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


However, when I make a call to move to the first row in the database, I receive a NullPointerException:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  c.moveToFirst();
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Edit: To make it clear, I am able to store the longitude, latitude and time in millis in the database, I am just unable to retrieve the data via a cursor.

I can provide more code if needed, but I would greatly appreciate any help.

Thanks
Lordsnoutimus
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sat Oct 17, 2009 10:05 am

Top

hi

Postby bingxuewangzi427 » Fri Mar 19, 2010 2:17 am

Do you add something of GPS promission in your Manifast file?
bingxuewangzi427
Developer
Developer
 
Posts: 38
Joined: Tue Jan 26, 2010 11:33 am

Postby Lordsnoutimus » Fri Mar 19, 2010 2:39 am

Hi,

Thanks for the reply.

I have the correct permissions in the manifest to allow GPS to be enabled, but that is not the problem. I can receive GPS coordinates and store them in a database, the problem occurs when I want to retrieve data from the database and show the coordinates on the map view.
Lordsnoutimus
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sat Oct 17, 2009 10:05 am

Re: NullPointerException with cursor

Postby bingxuewangzi427 » Fri Mar 19, 2010 3:09 am

Lordsnoutimus wrote:Hi,

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  Cursor c = getContentResolver().query(GPSContentProvider.CONTENT_URI, null, null, null, null); startManagingCursor(c);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


However, when I make a call to move to the first row in the database, I receive a NullPointerException:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  c.moveToFirst();
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Edit: To make it clear, I am able to store the longitude, latitude and time in millis in the database, I am just unable to retrieve the data via a cursor.

I can provide more code if needed, but I would greatly appreciate any help.

Thanks


Hi:
NullPointerException mean the problem with the datebase,I have encountered the same problem ever..
My problem is when I created the datebase,Can you show me your database manage file and more log mesages?

I think it's not a big problem,it's your java code bugs only..
bingxuewangzi427
Developer
Developer
 
Posts: 38
Joined: Tue Jan 26, 2010 11:33 am

Postby Lordsnoutimus » Fri Mar 19, 2010 12:02 pm

Below is the output I get from the logcat:

03-19 11:00:42.342: INFO/ActivityManager(577): Starting activity: Intent { comp={James.android.prototype/James.android.prototype.ShowLocation} }
03-19 11:00:42.612: ERROR/ActivityThread(797): Failed to find provider info for com.google.settings
03-19 11:00:42.773: DEBUG/LocationManager(797): Constructor: service = android.location.ILocationManager$Stub$Proxy@43763360
03-19 11:00:42.795: DEBUG/GpsLocationProvider(577): setMinTime 0
03-19 11:00:43.252: DEBUG/AndroidRuntime(797): Shutting down VM
03-19 11:00:43.262: WARN/dalvikvm(797): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
03-19 11:00:43.282: ERROR/AndroidRuntime(797): Uncaught handler: thread main exiting due to uncaught exception
03-19 11:00:43.302: ERROR/AndroidRuntime(797): java.lang.RuntimeException: Unable to start activity ComponentInfo{James.android.prototype/James.android.prototype.ShowLocation}: java.lang.NullPointerException
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.os.Looper.loop(Looper.java:123)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.app.ActivityThread.main(ActivityThread.java:3948)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at java.lang.reflect.Method.invoke(Method.java:521)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at dalvik.system.NativeStart.main(Native Method)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): Caused by: java.lang.NullPointerException
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at James.android.prototype.ShowLocation.onCreate(ShowLocation.java:50)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
03-19 11:00:43.302: ERROR/AndroidRuntime(797): ... 11 more
03-19 11:00:43.322: INFO/Process(577): Sending signal. PID: 797 SIG: 3
03-19 11:00:43.322: INFO/dalvikvm(797): threadid=7: reacting to signal 3
03-19 11:00:43.552: INFO/dalvikvm(797): Wrote stack trace to '/data/anr/traces.txt'
Lordsnoutimus
Junior Developer
Junior Developer
 
Posts: 16
Joined: Sat Oct 17, 2009 10:05 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 20 guests