Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Fatal Exception Timer-0
    primarykey
    data
    text
    <p>Here is the errors I'm getting</p> <pre><code>11-03 03:03:02.380: W/dalvikvm(1381): threadid=9: thread exiting with uncaught exception (group=0x40015560) 11-03 03:03:02.400: E/AndroidRuntime(1381): FATAL EXCEPTION: Timer-0 11-03 03:03:02.400: E/AndroidRuntime(1381): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 11-03 03:03:02.400: E/AndroidRuntime(1381): at android.os.Handler.&lt;init&gt;(Handler.java:121) 11-03 03:03:02.400: E/AndroidRuntime(1381): at android.location.LocationManager$ListenerTransport$1.&lt;init&gt;(LocationManager.java:173) 11-03 03:03:02.400: E/AndroidRuntime(1381): at android.location.LocationManager$ListenerTransport.&lt;init&gt;(LocationManager.java:173) 11-03 03:03:02.400: E/AndroidRuntime(1381): at android.location.LocationManager._requestLocationUpdates(LocationManager.java:579) 11-03 03:03:02.400: E/AndroidRuntime(1381): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:446) 11-03 03:03:02.400: E/AndroidRuntime(1381): at com.colinlgray.MyService$1.run(MyService.java:84) 11-03 03:03:02.400: E/AndroidRuntime(1381): at java.util.Timer$TimerImpl.run(Timer.java:284) </code></pre> <p>Here is my service that I am trying to run with a timer inside of it to update GPS location which I was planning on using to send to a webserver</p> <pre><code>package com.colinlgray; import android.app.Service; import android.content.Intent; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.widget.Toast; import java.util.Timer; import java.util.TimerTask; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import com.google.android.maps.GeoPoint; import android.content.Context; public class MyService extends Service{ int counter = 0; static final int UPDATE_INTERVAL = 1000; private Timer timer = new Timer(); GeoPoint geopoint; private LocationManager lm; private LocationListener locationListener; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { // We want this service to continue running until it is explicitly // stopped, so return sticky. Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show(); doSomethingRepeatedly(); return START_STICKY; } private void doSomethingRepeatedly() { timer.scheduleAtFixedRate( new TimerTask() { public void run() { lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); class MyLocationListener implements LocationListener{ public void onLocationChanged(Location location) { geopoint = new GeoPoint( (int) (location.getLatitude() * 1E6), (int) (location.getLongitude() * 1E6)); double latitude = location.getLatitude(); double longitude = location.getLatitude(); double altitude = location.getAltitude(); double accuracy = location.getAccuracy(); Log.d("LONGITUDE", String.valueOf(longitude)); Log.d("LATITTUDE", String.valueOf(latitude)); } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } } locationListener= new MyLocationListener(); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener); } }, 0, UPDATE_INTERVAL); } @Override public void onDestroy() { super.onDestroy(); if (timer != null){ timer.cancel(); } Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show(); } } </code></pre> <p>I would appreciate any help or suggestions at all. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload