i am using a mysql database in a host, i want recive a data from my host but when i get the data to a textview, it is in blank.
public class MainActivity extends Activity {
TextView tv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=(TextView)findViewById(R.id.name);
Loader loader = new Loader(getApplicationContext());
tv1.setText(loader.loadInBackground());
}
public static class Loader extends AsyncTaskLoader<String>{
public Loader (Context contexto)
{
super(contexto);
}
@Override
public String loadInBackground() {
String resultado = "";
String entrada = "";
DefaultHttpClient cliente = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://comupunt.esy.es/cities.php");
try {
HttpResponse execute = cliente.execute(httpget);
InputStream contenido = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(contenido));
String s="";
while((s=buffer.readLine())!=null)
resultado+=s;
{
}
} catch (Exception e) {
// TODO: handle exception
}
try {
JSONObject object = new JSONObject(resultado);
JSONArray jarray = object.getJSONArray("cities");
for (int i=0;i<jarray.length();i++)
{
JSONObject jobject = jarray.getJSONObject(i);
String name=jobject.getString("name");
entrada += name;
}
} catch (Exception e) {
// TODO: handle exception
Log.e("WebService", e.getMessage());
}
return entrada;
}
}
}
the php with json get this
{"cities":[{"name":"aitor"}]}
and the logcat:
12-02 04:24:01.492: E/WebService(2190): End of input at character 0 of
thanks