Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyncTask and Looper.prepare() error
    primarykey
    data
    text
    <p>I have the following code</p> <pre><code>class OverlayTask extends AsyncTask&lt;Void, Void, Void&gt; { @Override public void onPreExecute() { if (sites != null) { myMapView.getOverlays().remove(sites); myMapView.invalidate(); sites = null; } } @Override public Void doInBackground(Void... unused) { grabShipsWithLocation(); return (null); } @Override public void onPostExecute(Void unused) { myMapView.getOverlays().add(sites); myMapView.invalidate(); isLoading = false; } } </code></pre> <p>That seems to work fine on a few test devices but I am seeing a lot of errors appearing on the dev console. I can't seem to work out why and where to put this Looper.prepare(). Is it needed?</p> <pre><code>java.lang.ExceptionInInitializerError at com.test.appname.FinderMain$1.gotLocation(FinderMain.java:286) at com.test.appname.MyLocation$GetLastLocation.run(MyLocation.java:89) at java.util.Timer$TimerImpl.run(Timer.java:289) Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() at android.os.Handler.&lt;init&gt;(Handler.java:121) at android.os.AsyncTask$InternalHandler.&lt;init&gt;(AsyncTask.java:421) at android.os.AsyncTask$InternalHandler.&lt;init&gt;(AsyncTask.java:421) at android.os.AsyncTask.&lt;clinit&gt;(AsyncTask.java:152) </code></pre> <p>As requested MyLocation.java</p> <pre><code> class GetLastLocation extends TimerTask { @Override public void run() { lm.removeUpdates(locationListenerGps); lm.removeUpdates(locationListenerNetwork); Location net_loc=null, gps_loc=null; if(gps_enabled) gps_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if(network_enabled) net_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); //if there are both values use the latest one if(gps_loc!=null &amp;&amp; net_loc!=null){ if(gps_loc.getTime()&gt;net_loc.getTime()) locationResult.gotLocation(gps_loc); else locationResult.gotLocation(net_loc); return; } if(gps_loc!=null){ locationResult.gotLocation(gps_loc); //Line 89 return; } if(net_loc!=null){ locationResult.gotLocation(net_loc); return; } locationResult.gotLocation(null); } } </code></pre>
    singulars
    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.
 

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