1

Eclipse で次のような問題が発生しています。

MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@413da0c0 that was originally added here

誰かがこれを以前に見たことがありますか、またはこの問題を解決する方法を知っていますか? 私はコードを何度も見てきましたが、それを解決するために何ができるかを理解していません。

ログキャット:

10-09 17:12:15.630: E/WindowManager(1829): Activity com.example.test.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@413da0c0 that was originally added here
10-09 17:12:15.630: E/WindowManager(1829): android.view.WindowLeaked: Activity com.example.test.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@413da0c0 that was originally added here
10-09 17:12:15.630: E/WindowManager(1829):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
10-09 17:12:15.630: E/WindowManager(1829):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
10-09 17:12:15.630: E/WindowManager(1829):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
10-09 17:12:15.630: E/WindowManager(1829):  at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
10-09 17:12:15.630: E/WindowManager(1829):  at android.view.Window$LocalWindowManager.addView(Window.java:537)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.Dialog.show(Dialog.java:278)
10-09 17:12:15.630: E/WindowManager(1829):  at com.example.test.MainActivity$MyTask.onPreExecute(MainActivity.java:56)
10-09 17:12:15.630: E/WindowManager(1829):  at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
10-09 17:12:15.630: E/WindowManager(1829):  at android.os.AsyncTask.execute(AsyncTask.java:511)
10-09 17:12:15.630: E/WindowManager(1829):  at com.example.test.MainActivity.onCreate(MainActivity.java:43)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.Activity.performCreate(Activity.java:4465)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1923)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1984)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.ActivityThread.access$600(ActivityThread.java:126)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1150)
10-09 17:12:15.630: E/WindowManager(1829):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 17:12:15.630: E/WindowManager(1829):  at android.os.Looper.loop(Looper.java:137)
10-09 17:12:15.630: E/WindowManager(1829):  at android.app.ActivityThread.main(ActivityThread.java:4456)
10-09 17:12:15.630: E/WindowManager(1829):  at java.lang.reflect.Method.invokeNative(Native Method)
10-09 17:12:15.630: E/WindowManager(1829):  at java.lang.reflect.Method.invoke(Method.java:511)
10-09 17:12:15.630: E/WindowManager(1829):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
10-09 17:12:15.630: E/WindowManager(1829):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
10-09 17:12:15.630: E/WindowManager(1829):  at dalvik.system.NativeStart.main(Native Method)

ソース:

public class MainActivity extends Activity {

    TextView tv;
    String url = "http://examplecloudurl.org/apps/users/results.cfm?lname=BAR&fname=FOO";
    String tr;
    Document doc;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv = (TextView) findViewById(R.id.TextView01);
        new MyTask().execute(url);
    }

    private class MyTask extends AsyncTask<String, Void, String> {

        ProgressDialog prog;

        String title = "";

        @Override
        protected void onPreExecute() {
            prog = new ProgressDialog(MainActivity.this);
            prog.setMessage("Loading....");
            prog.show();

        }

        @Override
        protected String doInBackground(String... params) {

            ImageView img = (ImageView) findViewById(R.id.imageView1);
            {
                try {




                    String imageURL = "http://0.tqn.com/d/webclipart/1/0/5/l/4/floral-icon-5.jpg";
                    HttpGet httpRequest = null;

                    httpRequest = new HttpGet(URI.create(imageURL));

                    HttpClient httpclient = new DefaultHttpClient();
                    HttpResponse response = (HttpResponse) httpclient
                            .execute(httpRequest);

                    HttpEntity entity = response.getEntity();
                    BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
                    InputStream input = b_entity.getContent();

                    Bitmap bitmap = BitmapFactory.decodeStream(input);

                    img.setImageBitmap(bitmap);

                    doc = Jsoup.connect(params[0]).get();
                    Element tableElement = doc.select(".datagrid").first();

                    Elements tableRows = tableElement.select("tr");
                    for (Element row : tableRows) {
                        Elements cells = row.select("td");
                        if (cells.size() > 0) {
                            title = cells.get(0).child(0).attr("href") + " ; "
                                    + cells.get(0).text() + "; "
                                    + cells.get(1).text() + "; "
                                    + cells.get(2).text() + "; "
                                    + cells.get(3).text();
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return title;
            }
        }


        public void main(String[] args) throws IOException
        {
            String url = "http://www.juventus.com/wps/poc?uri=wcm:oid:91da6dbb-4089-49c0-a1df-3a56671b7020";

            Document document = manuelRedirectHandler(url);

            Elements elements = document.getElementsByClass("juveShareImage");

            for (Element element : elements)
            {
                System.out.println(element.attr("src"));
            }

        }

        private Document manuelRedirectHandler(String url) throws IOException
        {
            org.jsoup.Connection.Response response = Jsoup.connect(url.replaceAll(" ", "%20")).followRedirects(false).execute();
            int status = response.statusCode();

            if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER)
            {
                String redirectUrl = response.header("location");
                System.out.println("Redirect to: " + redirectUrl);
                return manuelRedirectHandler(redirectUrl);
            }

            return Jsoup.parse(response.body());
        }

        @Override
        protected void onPostExecute(String title) {
            super.onPostExecute(title);
            prog.dismiss();
            tv.setText(title);

        }

    }
}

編集(最初の応答後):

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tv = (TextView) findViewById(R.id.TextView01);
    new MyTask().execute(url);
}

private class MyTask extends AsyncTask<String, Void, String> {

    ProgressDialog prog;

    String title = "";

    @Override
    protected void onPreExecute() {
        prog = new ProgressDialog(MainActivity.this);
        prog.setMessage("Loading....");
        prog.show();

    }

    @Override
    protected String doInBackground(String... params) {


        {
            return title;
        }
    }


    public void main(String[] args) throws IOException
    {
        String url = "http://www.juventus.com/wps/poc?uri=wcm:oid:91da6dbb-4089-49c0-a1df-3a56671b7020";

        Document document = manuelRedirectHandler(url);

        Elements elements = document.getElementsByClass("juveShareImage");

        for (Element element : elements)
        {
            System.out.println(element.attr("src"));
        }

    }

    private Document manuelRedirectHandler(String url) throws IOException
    {
        org.jsoup.Connection.Response response = Jsoup.connect(url.replaceAll(" ", "%20")).followRedirects(false).execute();
        int status = response.statusCode();

        if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM || status == HttpURLConnection.HTTP_SEE_OTHER)
        {
            String redirectUrl = response.header("location");
            System.out.println("Redirect to: " + redirectUrl);
            return manuelRedirectHandler(redirectUrl);
        }

        return Jsoup.parse(response.body());
    }

    protected void onPostExecute(String... params) {
        super.onPostExecute(title);
        prog.dismiss();
        tv.setText(title);

        try {




            String imageURL = "http://0.tqn.com/d/webclipart/1/0/5/l/4/floral-icon-5.jpg";
            HttpGet httpRequest = null;

            httpRequest = new HttpGet(URI.create(imageURL));

            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response = (HttpResponse) httpclient
                    .execute(httpRequest);

            HttpEntity entity = response.getEntity();
            BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
            InputStream input = b_entity.getContent();

            Bitmap bitmap = BitmapFactory.decodeStream(input);

            img.setImageBitmap(bitmap);

            doc = Jsoup.connect(params[0]).get();
            Element tableElement = doc.select(".datagrid").first();

            Elements tableRows = tableElement.select("tr");
            for (Element row : tableRows) {
                Elements cells = row.select("td");
                if (cells.size() > 0) {
                    title = cells.get(0).child(0).attr("href") + " ; "
                            + cells.get(0).text() + "; "
                            + cells.get(1).text() + "; "
                            + cells.get(2).text() + "; "
                            + cells.get(3).text();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}

}

4

1 に答える 1

0

ImageView を取得して、AsyncTask の doInBackground で操作しようとしています。これはノーノーです。

これとそれへのすべての参照は、doInBackground() に含めるべきではありません。

ImageView img = (ImageView) findViewById(R.id.imageView1);

AsyncTaskのAndroid ドキュメントを読み、いくつかの例についてグーグルで検索してください。

基本的にやりたいことは、ビットマップを doInBackground() から AsyncTask の postExecute() に返すことです。次に、そこでビットマップを使用して ImageView を設定できます。

また、Android AsyncTask クラスに main() があるのはなぜですか?

于 2013-10-09T21:22:03.143 に答える