Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MainActivity已泄漏了window com.android.internal.policy.impl.PhoneWindow$DecorView@413da0c0原来是加在这里的_Java_Android_Memory Leaks_Logcat_Forceclose - Fatal编程技术网

Java MainActivity已泄漏了window com.android.internal.policy.impl.PhoneWindow$DecorView@413da0c0原来是加在这里的

Java MainActivity已泄漏了window com.android.internal.policy.impl.PhoneWindow$DecorView@413da0c0原来是加在这里的,java,android,memory-leaks,logcat,forceclose,Java,Android,Memory Leaks,Logcat,Forceclose,我在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): Activ

我在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();
        }

    }

}

}

您正在抓取一个ImageView,并试图在异步任务的后台操作它。这是个禁忌

这一点以及对它的所有引用不应出现在doInBackground中:

ImageView img = (ImageView) findViewById(R.id.imageView1);
通读并通过谷歌搜索一些例子

基本上,您要做的是将位图从doInBackground返回到AsyncTask的postExecute。然后,可以使用位图设置ImageView

为什么android AsyncTask类中有一个main?

您是否在任务完成之前关闭活动?