0
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的,但我可以看到應用程序運行
什麼是堆棧跟蹤?什麼是字符串結果的輸出?更多信息將不勝感激。 – kkudi 2011-03-28 17:30:50
發佈logcat。這條線可能是錯誤的。 result1.findViewById(R.id.result1); – 2011-03-28 17:37:18