0

上記のコードを使用して、ウェブホストから情報を取得しています。不思議ですが、スクリプトはAVDでは正常に機能しますが、実際のデバイス(Samsung Galaxy Note)では機能しません。例外はスローされません。

try{
    HttpClient htClient = getHttpClient();
    HttpPost htPost = new HttpPost("http://myworkingurl/access.php"); 
    Log.i("MyLog", "Print 1");  // this is outputed to LogCat
    HttpResponse htResponse = htClient.execute(htPost);
    Log.i("MyLog", "Print 2"); // no output here
} catch (ClientProtocolException ce) {
    Log.i("MyLog", ce.getMessage()); // no output here
} catch (IOException e) {
    Log.i("MyLog", e.getMessage()); // no output here
}

LogCatにエラーはありません。「Print1」を出力し、tryブロック内の残りのすべてのコードをジャンプし、このメソッドを呼び出すクラスは、voidメッセージを含む例外をスローします。注:uses-sdkの後にuses-permissionタグandroid.permission.INTERNETを配置し、エミュレーターで正常に動作します。

助けてください!

4

1 に答える 1

0

asyncTaskで同じコードを試してみてください。厳密モードが原因である可能性があります。

class ARequestTask extends AsyncTask<String, String, String>{

        @Override
        protected String doInBackground(String... params) {
         //http request here
        //return the response as string
         }
       @Override
       protected void onPostExecute(String result) {
          // use the result as you wish
       }
于 2012-11-09T18:41:23.733 に答える