在android中,我正在为url连接创建线程。在线程内部,我将响应消息存储在一个全局声明的字符串中。当我访问方法方法时,它返回null。
public class Rate_fetch {
String total="";
public String rate(String dt)
{
new Thread(new Runnable(){
public void run(){
try {
URL url = new URL(tally_ipaddr+"/prorate.jsp?plist="+sss.toString().trim());
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String x = "";
String total = "";
x = r.readLine();
int i=0;
while(x.length()>1)
{
total=total+x.toString().trim();
i++;
x = r.readLine();
}
}
catch(Exception e){
return e.toString();
}
}
}).start();
return total;
}
当我调用该方法时,它返回 null。
Rate_fetch rf=new Rate_fetch();
String amt= rf.rate(prodList);