Note that there are some explanatory texts on larger screens.

plurals
  1. POAlert Dialog Error in Android app
    primarykey
    data
    text
    <p>I'm having problems properly displaying an alert in my Android app. The goal is to send GPS coordinates to a database, but first check to see if the user is in a defined area. If the user is outside of the area, I want to display the alert. I keep getting problems on the line <code>AlertDialog.Builder alert = new AlertDialog.Builder(this);</code> with the error <code>The constructor AlertDialog.Builder(new LocationListener(){}) is undefined</code> I asked a similar question previously, but the solutions did not work and I think it's because I failed to include enough code. I'd appreciate any suggestions! </p> <pre><code> import java.io.BufferedReader; public class FindLocation { protected static final Context SendLocation = null; private LocationManager locManager; private LocationListener locListener; private class SendLocation extends AsyncTask&lt;String, Void, String&gt; { protected String doInBackground(String... params) { String lat = params[0]; String lon = params[1]; String usr_id2 = params[2]; HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://example.com/example.php"); try { List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("lat", lat)); nameValuePairs.add(new BasicNameValuePair("lon", lon)); nameValuePairs.add(new BasicNameValuePair("id", usr_id2)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httpclient.execute(httppost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return lon; } } public void startLocation(Context context, String usr_id2) { //changed context to final when AlertDialog was added final String usr = usr_id2; //get a reference to the LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); //checked to receive updates from the position locListener = new LocationListener() { public void onLocationChanged(Location loc) { String lat = String.valueOf(loc.getLatitude()); String lon = String.valueOf(loc.getLongitude()); Double latitude = loc.getLatitude(); Double longitude = loc.getLongitude(); if (latitude &gt;= 39.15296 &amp;&amp; longitude &gt;= -86.547546 &amp;&amp; latitude &lt;= 39.184901 &amp;&amp; longitude &lt;= -86.504288) { Log.i("Test", "Yes"); CityActivity check = new CityActivity(); check.checkDataBase(usr); SendLocation task = new SendLocation(); task.execute(lat, lon, usr); } else { Log.i("Test", "No"); AlertDialog.Builder alert = new AlertDialog.Builder(this); //****error here***** alert.setTitle("Warning"); alert.setMessage("Sorry"); alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions } }); alert.show(); } } public void onProviderDisabled(String provider){ } public void onProviderEnabled(String provider){ } public void onStatusChanged(String provider, int status, Bundle extras){ } }; locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, locListener); } </code></pre>
    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.
 

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