Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This is important</strong></p> <pre><code>EXCEPTION: main 04-14 02:41:42.782: ERROR/AndroidRuntime(13759): java.lang.NullPointerException ERROR/AndroidRuntime(13759): at com.irwine.touristapplication.MyLocOverlay.draw(MyLocOverlay.java:23) </code></pre> <p>if I had to guess, I'd say that your location is null. Try running in debug mode and see what you can find. My suggestion is put a break point BEFORE the error line and look at what the variables are.. if your location variable is null, that is your problem, way to fix this is to keep pinging until you get it..</p> <p>The solution is to check if the location is null.. if its null, then this means you need to request the location again. If you try pinging for 20s and don't get anything, keep pinging until you get something. Ideally you want it to time out after 5 tries... <strong>This is because if you ping constantly the user will hate you</strong>. However; If 100s pass and you don't get a location, then time out and have the user request that location again or ask them to try again later.</p> <p><strong>UPDATE</strong></p> <p>Specifically, i see an error with this. Here is how I would approach it:</p> <p>Request the location -> Wait for the location through the location listener -> Once the locations received then update the overlay. </p> <p>Keep requesting as long as the location returned is null. Time out like I said.</p> <p>Here is an example:</p> <p>my LocationListener class:</p> <pre><code>public class myLocationListener implements LocationListener { Location L; public void onLocationChanged(Location arg0) { Toast.makeText(getApplicationContext(), "Location has changed", Toast.LENGTH_SHORT).show(); L = arg0; updateNewLocation(L); }} </code></pre> <p>Function I call:</p> <pre><code>public void updateNewLocation(Location loc) { // while the location is not null get latitude and longitude // information // :: Null means that the GPS provider is off or there is an issue if (loc != null) {}} </code></pre> <p>Function body I use to request location along with timeout:</p> <pre><code>Toast.makeText(getApplicationContext(), "Searching for your location.", Toast.LENGTH_SHORT) .show(); locationManager.requestLocationUpdates(provider, 20000, 5, locationListener); // Thread to count until timeout (15 * 5000ms) Thread t = new Thread(new Runnable() { public void run() { count = 0; for (int i = 0; i &lt; 15; i++) { if (locationListener.L == null) { try { handler.sendMessage(handler .obtainMessage()); Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } } } </code></pre> <p>Handler to help with timeout</p> <pre><code>Handler handler = new Handler() { @Override public void handleMessage(Message msg) { count++; if (count == 15) { error(); count = 0; } } }; </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.
    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