我一直在寻找很长时间来回答我的简单问题,但还没有找到。
我刚刚开始 Android 开发,我无法将这个简单的 XML布局到我刚刚创建的 Android 应用程序中。
有我的代码:
public class MainActivity extends Activity {
private static final String TAG = null;
/** Called when the activity is first created. */
private String getPage() {
String str = null ;
Log.v(TAG, "testentreemethode");
try
{
HttpClient hc = new DefaultHttpClient();
Log.v(TAG, "testnew");
HttpPost post = new HttpPost("http://www.3pi.tf/test.xml");
Log.v(TAG, "testurl");
HttpResponse rp = hc.execute(post);
Log.v(TAG, "testpost");
if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
{
str = EntityUtils.toString(rp.getEntity());
}
}catch(IOException e){
e.printStackTrace();
}
return str;
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txt = (TextView) findViewById(R.id.textview1);
Log.v(TAG, "test1");
txt.setText(getPage());
Log.v(TAG, "test2");
}
}
如您所见,我放了一些 Logcat 来查看“光标”的位置,但它无法通过此行:
HttpResponse rp = hc.execute(post);
有人能帮助我吗?