1

Web サービスを呼び出すために、xml レイアウトでリストビューを作成し、インターネットのアクセス許可を与え、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