IO.Exception在logcat的,但我可以看到应用程序运行
问题描述:
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当我运行代码与服务器活着。IO.Exception在logcat的,但我可以看到应用程序运行
答
您看不到“结果”的值,因为在达到Log.i("GET RESPONSE",result);
之前抛出异常。修复抛出的异常中描述的问题,您将看到您的结果。
此外,而不是在写catch
e.printStackTrace();
,写的是这样的:
Log.e("MY TAG", e.toString(), e);
什么是堆栈跟踪?什么是字符串结果的输出?更多信息将不胜感激。 – kkudi 2011-03-28 17:30:50
发布logcat。这条线可能是错误的。 result1.findViewById(R.id.result1); – 2011-03-28 17:37:18