【发布时间】:2011-03-28 17:26:54
【问题描述】:
public class tryget extends Activity
{
TextView result1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i("GET RESPONSE","result outside");
try
{
HttpClient client = new DefaultHttpClient();
String getURL = "http://10.0.2.2:8888/mainserver1/androidservlet";
HttpGet get = new HttpGet(getURL);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null)
{
InputStream is = resEntityGet.getContent();
String s=is.toString();
byte[] bytes =s.getBytes();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
String result = (String) in.readObject();
result1=(TextView)findViewById(R.id.result1);
result1.setText(s);
result1.findViewById(R.id.result1);
//do something with the response
//Log.i("GET RESPONSE",EntityUtils.getContentCharSet(resEntityGet));
Log.i("GET RESPONSE",result);
// in.close();
is.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
我可以看到应用程序在模拟器中运行,但我看不到包含“结果”值的文本字段,在其空间中没有任何内容出现,并且当我在服务器活动的情况下运行代码时,Logcat 显示 IO.exception。
【问题讨论】:
-
什么是堆栈跟踪? String 结果的输出是什么?更多信息将不胜感激。
-
发布日志猫。这条线可能是错误的。 result1.findViewById(R.id.result1);
标签: android http client-server