android - 如何调试 AsyncTask.doInBackground?
问题描述
我想在 android studio 中使用异步任务在与我相同的网络上执行 php 脚本并获得结果。
private class HTTPReqTask extends AsyncTask<String, String, String> {
String temp = new String();
@Override
protected String doInBackground(String... strings) {
HttpURLConnection urlConnection = null;
try {
URL url = new URL("PHPSCRIBT" + strings[0]);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
int status = con.getResponseCode();
StringBuilder sb = new StringBuilder();
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((line = br.readLine()) != null) {
sb.append(line);
}
temp = sb.toString();
Log.d("myTag", temp);
con.disconnect();
} catch (Exception e) {
}
return temp;
}
protected void onPostExecute(String temp) {
TextView textView = (TextView) findViewById(R.id.textView5);
try {
String erstezahl = temp.split("\\{")[0];
String jsonstring = temp.substring(temp.indexOf("{") - 1);
JSONObject json = new JSONObject(jsonstring);
int amount = Integer.valueOf(erstezahl);
textView.setText(amount);
} catch (Exception e) {
String error = "ERROR +" + temp + "+" + e.toString();
textView.setText(error);
}
}
}
我的 onPostExecute() 函数获取一个空字符串作为参数。因此,我想调试我的 doInBackground 函数。做这个的最好方式是什么?
解决方案
推荐阅读
- laravel - 如何在 laravel 中创建种子层次结构
- java - 错误 java.lang.NoClassDefFoundError:Java 11 中的 javax/jws/WebService
- laravel - Laravel 调度程序在 tmp 文件夹中创建数千个日志文件
- html - HTML - “&”在评估过程中丢失
- algorithm - 为什么AA树做运算是先倾斜再分裂?
- jenkins - Jenkins 声明性管道阻塞作业
- elasticsearch - 启动 node_data 时 Elasticsearch node_master 变为离线
- css - 如何使共享类名的两个 CSS 元素不同?
- coldfusion - Cold Fusion 2018:如何将 .xlsx 文件另存为 .csv
- javascript - 如何使用 Vuejs 在 Safari 中侦听表单上的粘贴事件