1

为了调用 Web 服务,我在 xml 布局中创建了一个列表视图,我授予了 Internet 权限,并使用了 stackoverflow 中给出的代码,

 HttpHost target = new HttpHost(ServiceWrapper.SERVER_HOST,ServiceWrapper.SERVER_PORT);
    HttpGet get = new HttpGet("/list");
    String result=null;
    HttpEntity entity = null;
    HttpClient client = new DefaultHttpClient();
    try {
      HttpResponse response=client.execute(target, get);
      entity = response.getEntity();
      result = EntityUtils.toString(entity);
     } catch (Exception e) {
      e.printStackTrace();
     } finally {
      if (entity!=null)
       try {
        entity.consumeContent();
       } catch (IOException e) {}
     }
     return return;
}

xml布局代码是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_width="match_parent" 
    android:id="@+id/listView1"
    android:layout_height="match_parent" 
    android:scrollingCache="false"
    android:background="#ffffff" 
    android:cacheColorHint="#00000000">
</ListView>

但是在这里我在 ServiceWrapper 中遇到错误,我是否必须包含任何其他类?有任何想法吗?

4

0 回答 0