我正在尝试与rest api进行通信以检索JSON文档,但是当我在Eclipse Android模拟器中运行应用程序时,应用程序一启动就关闭("不幸的是TestRest已经停止").由于调用了httpClient.execute方法,它似乎关闭了.
主要活动的代码如下:
public class TestRestActivity extends Activity {
/** Called when the activity is first created. */
TextView info;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
info = (TextView) findViewById(R.id.debug);
String testUri = "http://www.entireweb.com/xmlquery?pz=MYAPIKEY&ip=IP&q=pizza&n=50&format=json";
// print the uri to the screen - (not seen if rest of code runs)
info.setText(testUri);
HttpClient httpclient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpget = new HttpGet(testUri);
HttpResponse response = null;
try {
// TODO fails on this line …Run Code Online (Sandbox Code Playgroud)