0

HoneyCombデバイスを対象とするandroid.os.NetworkOnMainThreadExceptionのポイントを理解しましたが、次のコードは同じ例外をスローします。

class MakeRequest extends AsyncTask<String,Integer,Void>
    {

        @Override
        protected Void doInBackground(String... params) {
            DefaultHttpClient cli = new DefaultHttpClient();
            try {
                String url = params[0].replace(" ", "%20");
                HttpResponse resp = cli.execute(new HttpGet(url));
                BufferedReader read = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
                String tmp = "",rezultat = "";
                setResult("");

                while ((tmp = read.readLine()) != null)
                {
                    rezultat = rezultat + tmp;
                }
                setResult(rezultat);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                setResult("");
                return null;
            }
            return null;
        }
//Sample call
HttpRequester cc = new HttpRequester();
MakeRequest test = cc.new MakeRequest();
test.doInBackground(url);
4

1 に答える 1

0

これを試して。

new MakeRequest().execute(url);
于 2012-08-30T11:31:57.010 に答える