我希望有人能够找到这个问题。我有一个完全在服务器通信中工作的应用程序。不幸的是,当移动到Windows 8 CP时,我失去了Eclipse工作区。我仍然有.apk,并且使用Dex2jar和jd-gui,我能够挽救很多代码。我已经把所有这一切都恢复到了工作状态,但是这一点。我试图发送一个URL到服务器,并取回字符串响应。这里的代码:Android HTTP客户端问题
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class login extends Activity{
<code>
public void pushLogin(View paramView){
try{
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(loginFinal);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
errorTextView.setText(loginFinal);
//code gets here
String response = client.execute(request, responseHandler);
//does not get here
errorTextView.setText(response);
}
我的TextView总是包含字符串loginFinal,我不能让它显示响应。为了检查这一点,我在尝试获取字符串响应后将errorTextView.setText(loginFinal);
移至了行。它也没有在这一点上运行。我正在撕掉我的头发,我确信这很简单。我已经获得了互联网许可,我甚至在这个网站上发现了我的这个应用程序部分的原始代码,因为我发布了一个单独的问题。就我所知,此代码是相同的。我能想到的唯一变化就是我将我的构建目标从Froyo移到了Honeycomb,因为我决定要专注于平板电脑。
最好的部分是,当我按下按钮,触发pushLogin时,LogCat什么也不做。它似乎并没有触发client.execute(request, responseHandler)
。
为什么不检查client.execute以查看它是否引发异常。你确定服务器启动,你想联系? – dbryson 2012-03-06 03:39:42
try {}之后的catch块中有什么?如果你说它不在client.execute后面执行,我必须假设它正在发生异常。你有没有在调试器中加入? – Tim 2012-03-06 03:39:52
我有一个catch方法。我对此仍然非常陌生,但我觉得这应该为某种形式的错误加油印象。 'catch(Exception e){ Toast.makeText(this,e.getMessage(),Toast.LENGTH_LONG);' 我从来没有得到错误的敬酒。有什么问题吗? – 2012-03-06 04:26:56