Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyntask #1 Android error
    text
    copied!<p><strong>NEW VERSION 1.1</strong></p> <p>Hi guys. I tried to follow your recommendations and now i'm trying to redo the code. I added this part of the code to work on the Main Thread the GoogleMaps markers.</p> <p>The problem is, when i call the Ubic() function, i get this error:</p> <p><a href="http://i.imgur.com/QD7JZjRh.jpg" rel="nofollow">http://i.imgur.com/QD7JZjRh.jpg</a></p> <p><a href="http://i.imgur.com/xvzJ9ckh.jpg" rel="nofollow">http://i.imgur.com/xvzJ9ckh.jpg</a></p> <p>This is the code that i added an the error is caused by String Latlon[][] = com.Ubic(); </p> <pre><code>public class BuscarContrincantes extends FragmentActivity implements LocationListener { GoogleMap googlemapa; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.buscarcontrincante); SupportMapFragment maps = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); googlemapa = maps.getMap(); googlemapa.setMyLocationEnabled(true); googlemapa.setMapType(GoogleMap.MAP_TYPE_HYBRID); googlemapa.getUiSettings().setCompassEnabled(true); googlemapa.getUiSettings().setZoomControlsEnabled(true); googlemapa.getUiSettings().setAllGesturesEnabled(true); double latitud; double longitud; String nombre; Datos com = new Datos(); String latlon[][] = com.Ubic(); //HERE IS THE PROBLEM! for (int i = 0; i &lt; latlon.length - 1; i++) { latitud = Double.parseDouble(latlon[i][0]); longitud = Double.parseDouble(latlon[i][3]); nombre = (latlon[i][2]); LatLng posicion = new LatLng(latitud, longitud); googlemapa.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory .fromResource(R.drawable.icono_canchas)) .position(posicion).title(nombre)); } } </code></pre> <hr> <p><strong>VERSION 1.0</strong></p> <p>I'm having a problem with a project that i'm doing for my college.</p> <p>Actually, i'm trying to set a Marker on a Map (With Google Maps) that his information is on a MySQL Database.</p> <p>The code is:</p> <p>BuscarContrincantes.java</p> <pre><code>public class BuscarContrincantes extends FragmentActivity implements LocationListener { GoogleMap googlemapa; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.buscarcontrincante); SupportMapFragment maps = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); googlemapa = maps.getMap(); googlemapa.setMyLocationEnabled(true); googlemapa.setMapType(GoogleMap.MAP_TYPE_HYBRID); googlemapa.getUiSettings().setCompassEnabled(true); googlemapa.getUiSettings().setZoomControlsEnabled(true); googlemapa.getUiSettings().setAllGesturesEnabled(true); new RetreiveFeedTask().execute(); } class RetreiveFeedTask extends AsyncTask&lt;String, Void, String&gt; { protected String doInBackground(String... args) { double lat; double lon; String nombre; Datos com = new Datos(); // File Datos.java String latlon[][] = com.Ubic(); for (int i = 0; i &lt; latlon.length - 1; i++) { lat = Double.parseDouble(latlon[i][0]); lon = Double.parseDouble(latlon[i][4]); nombre = (latlon[i][2]); LatLng pos3 = new LatLng(lat, lon); googlemapa.addMarker(new MarkerOptions() .icon(BitmapDescriptorFactory .fromResource(R.drawable.icono_canchas)) .position(pos3).title(nombre)); } return null; } } @Override public void onLocationChanged(Location arg0) { // TODO Auto-generated method stub }} </code></pre> <p>Datos.java</p> <pre><code>public class Datos { public String[][] Ubic() { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://MY.IP/FOLDER/QUERY.php"); try { HttpResponse response = httpclient.execute(httppost); String jsonResult = inputStreamToString( response.getEntity().getContent()).toString(); JSONObject object = new JSONObject(jsonResult); JSONArray arr = object.getJSONArray("products"); String[] lat = new String[arr.length()+1]; String[] lon = new String[arr.length()+1]; String[] nombre = new String[arr.length() + 1]; String[][] latlon = new String[arr.length() + 1][5]; for (int i = 0; i &lt; arr.length(); i++) { lat[i] = arr.getJSONObject(i).getString("latitude"); lon[i] = arr.getJSONObject(i).getString("longitude"); name[i] = arr.getJSONObject(i).getString("name"); latlon[i][0] = lat[i]; latlon[i][6] = lon[i]; latlon[i][2] = name[i]; } return latlon; } catch (JSONException e) { } catch (ClientProtocolException e) { } catch (IOException e) { } return null; } private static String parse(String string) { return null; } private StringBuilder inputStreamToString(InputStream is) { String rLine = ""; StringBuilder answer = new StringBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); try { while ((rLine = rd.readLine()) != null) { answer.append(rLine); } } catch (IOException e) { } return answer; }} </code></pre> <p>This code is trying to get Latitude, Longitude and Name of an object that is on a MySQL Database and must put this object on the Map, but i'm getting the AsynkTask #1 Error and i don't know why this is happening. ¿Can you help me, please? I'm getting really mad with this code and i don't know why this isn't working.</p> <p>P.S: Sorry for my bad English. I'm from Chile :P</p>
 

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