This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Android and the fly likes Runtime error when accessing Location data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Runtime error when accessing Location data" Watch "Runtime error when accessing Location data" New topic
Author

Runtime error when accessing Location data

John Danek
Greenhorn

Joined: Jun 12, 2009
Posts: 25
Hello all,

I'm writing my first Android app (besides Hello World) and am running into a tricky runtime error. When I try getting the location data to update a TextView, the emulator Force Quits my program. I have been tweaking my code for two hours and can't figure out the problem. Here's the method in my code that is access the data:




Here is my constructor for this class, where my LocationManager and Location objects are made:


Does anyone have an idea as to what the correct code would look like? Many thanks.
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

Have you added required permissions in the manifest file for using LocationService? Can you post exception logs?


[List of FAQs] | [Android FAQ] | [Samuh Varta]
John Danek
Greenhorn

Joined: Jun 12, 2009
Posts: 25
I added these to my manifest:



and I'm not exactly sure how to generate an exception log. I Googled "exception logging" but couldn't find anything appropriate.
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

If you are using Eclipse IDE, switch to DDMS perspective and you will get the logs in "LogCat" view.[Take some time to read this article ].

You can also use DDMS tool bundled with the SDK (inside SDK_installation/tools) or use adb to get the logs. FYI, the command is: adb logcat

John Danek
Greenhorn

Joined: Jun 12, 2009
Posts: 25
I will do that as soon as I am done with class for the day and post it on here. Thanks for your help!
John Danek
Greenhorn

Joined: Jun 12, 2009
Posts: 25
Ok, here is my log obtained from LogCat:

04-08 18:45:36.898: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)
04-08 18:45:36.898: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)
04-08 18:45:36.898: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)
04-08 18:45:36.898: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)
04-08 18:45:46.718: ERROR/BatteryService(51): usbOnlinePath not found
04-08 18:45:46.718: ERROR/BatteryService(51): batteryVoltagePath not found
04-08 18:45:46.718: ERROR/BatteryService(51): batteryTemperaturePath not found
04-08 18:45:46.728: ERROR/SurfaceFlinger(51): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-08 18:45:49.898: ERROR/EventHub(51): could not get driver version for /dev/input/mouse0, Not a typewriter
04-08 18:45:49.898: ERROR/EventHub(51): could not get driver version for /dev/input/mice, Not a typewriter
04-08 18:45:49.998: ERROR/System(51): Failure starting core service
04-08 18:45:49.998: ERROR/System(51): java.lang.SecurityException
04-08 18:45:49.998: ERROR/System(51): at android.os.BinderProxy.transact(Native Method)
04-08 18:45:49.998: ERROR/System(51): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-08 18:45:49.998: ERROR/System(51): at android.os.ServiceManager.addService(ServiceManager.java:72)
04-08 18:45:49.998: ERROR/System(51): at com.android.server.ServerThread.run(SystemServer.java:176)
04-08 18:45:50.008: ERROR/AndroidRuntime(51): Crash logging skipped, no checkin service
04-08 18:45:58.105: ERROR/ActivityThread(92): Failed to find provider info for android.server.checkin
04-08 18:45:59.385: ERROR/ActivityThread(92): Failed to find provider info for android.server.checkin
04-08 18:45:59.505: ERROR/ActivityThread(92): Failed to find provider info for android.server.checkin
04-08 18:46:02.405: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound)
04-08 18:46:02.635: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound
04-08 18:46:02.655: ERROR/MediaPlayer(51): Unable to to create media player
04-08 18:46:06.776: ERROR/AndroidRuntime(121): ERROR: thread attach failed
04-08 18:46:11.385: ERROR/ActivityThread(51): Failed to find provider info for com.google.settings
04-08 18:46:11.385: ERROR/ActivityThread(51): Failed to find provider info for com.google.settings
04-08 18:46:11.695: ERROR/AndroidRuntime(185): ERROR: thread attach failed
04-08 18:46:14.674: ERROR/gralloc(51): [unregister] handle 0x11f9b8 still locked (state=40000001)
04-08 18:47:26.208: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test2' (No such file or directory)
04-08 18:47:26.208: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test2' (No such file or directory)
04-08 18:47:26.208: ERROR/vold(26): Error opening switch name path '/sys/class/switch/test' (No such file or directory)
04-08 18:47:26.208: ERROR/vold(26): Error bootstrapping switch '/sys/class/switch/test' (No such file or directory)
04-08 18:47:35.898: ERROR/BatteryService(51): usbOnlinePath not found
04-08 18:47:35.898: ERROR/BatteryService(51): batteryVoltagePath not found
04-08 18:47:35.898: ERROR/BatteryService(51): batteryTemperaturePath not found
04-08 18:47:35.908: ERROR/SurfaceFlinger(51): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
04-08 18:47:39.158: ERROR/EventHub(51): could not get driver version for /dev/input/mouse0, Not a typewriter
04-08 18:47:39.158: ERROR/EventHub(51): could not get driver version for /dev/input/mice, Not a typewriter
04-08 18:47:39.248: ERROR/System(51): Failure starting core service
04-08 18:47:39.248: ERROR/System(51): java.lang.SecurityException
04-08 18:47:39.248: ERROR/System(51): at android.os.BinderProxy.transact(Native Method)
04-08 18:47:39.248: ERROR/System(51): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
04-08 18:47:39.248: ERROR/System(51): at android.os.ServiceManager.addService(ServiceManager.java:72)
04-08 18:47:39.248: ERROR/System(51): at com.android.server.ServerThread.run(SystemServer.java:176)
04-08 18:47:39.248: ERROR/AndroidRuntime(51): Crash logging skipped, no checkin service
04-08 18:47:45.545: ERROR/ActivityThread(92): Failed to find provider info for android.server.checkin
04-08 18:47:46.715: ERROR/ActivityThread(92): Failed to find provider info for android.server.checkin
04-08 18:47:46.805: ERROR/ActivityThread(92): Failed to find provider info for android.server.checkin
04-08 18:47:49.116: ERROR/AndroidRuntime(117): ERROR: thread attach failed
04-08 18:47:51.205: ERROR/vold(26): Cannot start volume '/sdcard' (volume is not bound)
04-08 18:47:51.375: ERROR/MediaPlayerService(30): Couldn't open fd for content://settings/system/notification_sound
04-08 18:47:51.375: ERROR/MediaPlayer(51): Unable to to create media player
04-08 18:47:54.064: ERROR/AndroidRuntime(162): ERROR: thread attach failed
04-08 18:47:57.514: ERROR/ActivityThread(51): Failed to find provider info for com.google.settings
04-08 18:47:57.514: ERROR/ActivityThread(51): Failed to find provider info for com.google.settings
04-08 18:49:14.114: ERROR/AndroidRuntime(196): Uncaught handler: thread main exiting due to uncaught exception
04-08 18:49:16.755: ERROR/AndroidRuntime(196): java.lang.NullPointerException
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.ist444.BlackBox.threadAlternative(BlackBox.java:139)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.ist444.BlackBox$1.onClick(BlackBox.java:66)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.View.performClick(View.java:2364)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.View.onTouchEvent(View.java:4179)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.widget.TextView.onTouchEvent(TextView.java:6540)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.View.dispatchTouchEvent(View.java:3709)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.os.Handler.dispatchMessage(Handler.java:99)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.os.Looper.loop(Looper.java:123)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at java.lang.reflect.Method.invokeNative(Native Method)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at java.lang.reflect.Method.invoke(Method.java:521)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at dalvik.system.NativeStart.main(Native Method)
04-08 18:49:16.845: ERROR/dalvikvm(196): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

There appears to be a lot of errors, but I can't make much sense of it.
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

the part to focus on is :
04-08 18:49:16.755: ERROR/AndroidRuntime(196): java.lang.NullPointerException
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.ist444.BlackBox.threadAlternative(BlackBox.java:139)
04-08 18:49:16.755: ERROR/AndroidRuntime(196): at com.ist444.BlackBox$1.onClick(BlackBox.java:66)

Seems to me you are referencing a null value
John Danek
Greenhorn

Joined: Jun 12, 2009
Posts: 25
Ok, I attempted rewriting my code into a single class thinking it may simplify/help identify what problems I have. Here is my class:




I still run into the same result. Upon hitting the Start Button, I get the same "The application has stopped unexpectedly" dialog with the Force Close button. Here is my LogCat log:


I think it may be a problem with mock location data? My SDK doesn't have a /data/misc/location/gps directory.

Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

The problem here is that you have called setText() from a non-UI thread. A quick fix would be to wrap the setText() call around a context.runOnUiThread() inside the run function.
John Danek
Greenhorn

Joined: Jun 12, 2009
Posts: 25
Ok, I fixed by using a Handler to setText, but now it appears my StopButton isn't working because if I hit Stop, then Start again, it crashed and the LogCat says


Could it be that because the Thread is sleeping, the setStopTracking() method isn't being called?

Thanks for you patience with all of this. It is greatly appreciated. Upon completion of this problem, I will begin trying to respond to beginners' questions on the forum for karma's sake (and the Java community's!).
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

java.lang.IllegalThreadStateException: Thread already started.
Javadoc of Thread#start() method:
It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.

You have only one Thread referenced by runner, which you are trying to restart on click of Start Tracking button.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Runtime error when accessing Location data
 
Similar Threads
how to use distanceBetween built in methog
It prints me pointer repeatedly
street view & satilite view is not working
Cannot find the problem in the code
how to add a google search option