这是我在这个网站上的第一篇文章,我的应用程序有问题,我找不到我的应用程序停止的原因。我正在向 Despegar 发送请求以获取国家/地区的 json,但发生了这些。如果你能帮助我,我会非常高兴。
这是我的代码:
public class MainActivity extends Activity {
final TextView txtResultado = (TextView) findViewById(R.id.txtResultado);
String JSONRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new TareaConexion().execute("http://api.despegar.com/countries");
}
class TareaConexion extends AsyncTask<String, Void, String>{
protected void onPreExecute() {
}
protected String doInBackground(String... urls) {
httpHandler httphandler = new httpHandler();
JSONRequest = httphandler.Post(urls[0]);
return JSONRequest;
}
protected void onProgressUpdate () {
}
protected void onPostExecute() {
txtResultado.setText(JSONRequest);
}
}
和 httpHandler 类:
public class httpHandler {
public String Post (String PostURL)
{
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(PostURL);
HttpResponse resp = httpclient.execute(httppost);
HttpEntity ent = resp.getEntity();
String Respuesta = EntityUtils.toString(ent);
return Respuesta;
} catch (Exception e) {
return "error";
}
}
}
谁能找到我的应用停止的原因?我究竟做错了什么?
我是阿根廷人,如果我的语言有误,请见谅,ajja。谢谢