我在一个 Andriod 应用程序上工作。我从数据库中读取了一些字符串并在 ListView 中输出它们。我的问题是,如果我在逐步模式下,来自 DB 的返回字符串运行良好。如果我处于运行模式,或者即使我将断点放在收到结果的行之后。字符串变量将为空。
BackgroundWorker backgroundWorker = new BackgroundWorker( this);
backgroundWorker.execute("Names");
res = backgroundWorker.FinalRes;
res = res.replace("[","");
res = res.replace("]","");
res = res.replace("\"","");
ParsedStringsResult = PasrString(res);
ArrayList<ListNames> NameSs= new ArrayList<ListNames>();
int size = ParsedStringsResult.length;
for ( int i=0; i<size;i++ )
NameSs.add(new ListNames(ParsedStringsResult[i]));
如果我把断点放在 res=backgroundWorker.FinalRes;
它运行良好并显示值如果我把它放在这一行之后甚至在默认运行模式下, res 将为空!
为什么会发生这种情况,我该如何解决?
我的背景课
public class BackgroundWorker extends AsyncTask<String , Void, String> {
Context context;
public String FinalRes="";
AlertDialog alertDialog;
BackgroundWorker(Context ctx)
{
context = ctx;
}
@Override
protected String doInBackground(String... params) {
String type = params[0];
if (type == "Names") {
String url_login = "http://192.168.1.2/MyApp/getNames.php";
try {
URL url = new URL(url_login);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
/* OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("name", "UTF-8") + "=" + URLEncoder.encode(name, "UTF-8");// +"&"+ w nkml tany
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();*/
}
慕侠2389804
炎炎设计
相关分类