0

私は自分のphpファイルが機能することを知っています.localhostから呼び出すことができ、応答を得ることができます. また、AVD でブラウザーから URL を呼び出すと応答が返されるため、AVD から呼び出すための正しい IP アドレスがあることもわかっています。したがって、問題は私の asynctask 関数にあります。

asynctask クラスのコードは次のとおりです。

protected String doInBackground(String... args) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response;
    try {
        response = httpclient.execute(new HttpGet(url));
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return null;
}

protected void onPostExecute(String str) {
    // updating UI from Background Thread
    resp=str;
    returned();
}

親クラスからこのクラスを呼び出し、onpostexecute() からの文字列を、親クラスの文字列である文字列 resp に入れています。応答は常に null です。

4

1 に答える 1

2

さて、あなたは を返しnullているので、コードは書かれたとおりに機能しています。

の代わりにreturn nulldoInBackground()http 応答の一部を返したいですか?

于 2012-11-28T15:51:35.590 に答える