Reputation: 59
I'm trying to connect to mysql using AsyncTask in android but i am having complications. I'm using an interface to return data from AsyncTask, but when i run the code I get the following error: exception RuntimeException. Thank you very much to all.
Upvotes: 0
Views: 275
Reputation: 3800
Add a general Exception block to your JSON parsing try/catch and post the error that is caught:
//parse json data
try{
JSONArray jarray = new JSONArray(result);
for(int i=0 ; i<jarray.length() ; i++) {
JSONObject ob = jarray.getJSONObject(i);
String titulo = ob.getString("title");
String cate = ob.getString("catid");
int cat = Integer.parseInt(cate);
String coord = ob.getString("extra_fields_search");
String latitud = coord.substring(0, 9);
Float lat_f = Float.parseFloat(latitud);
int lat = lat_f *1000000;
String longitud = coord.substring(10, 19);
Float lon_f = Float.parseFloat(longitud);
int lon = lon_f*1000000;
GeoPoint point = new GeoPoint(lat, lon);
negocioNuevo = new Negocio(titulo, cat, point);
listaNegocios.add(negocioNuevo);
}
}catch(JSONException e){
Log.e("miError de JSON", "Error parsing JSON "+e.toString());
}catch(Exception e){
Log.e("miError de General", "Error parsing data "+e.toString());
}
Upvotes: 1
Reputation: 21
In the connection class try to replace
public Conexion(OnTaskCompleted listener){
this.listener=listener;
}
with
public void setOnResultsListener(OnTaskCompleted listener) {
this.listener = listener;
}
and then replace in MainActivity:
Conexion conexion = new Conexion(this);
conexion.execute("tipo");
with:
Conexion conexion = new Conexion();
conexion.setOnResultsListener(this);
conexion.execute("tipo");
Upvotes: 0