1

アクティビティで 3 つの進行状況ダイアログを使用します

  1. OnCreate()
  2. 次のページに移動するとき
  3. 前のページに移動するとき

しかし、最初に次のページボタンをクリックすると、アプリケーションがエラーでクラッシュしますWINDOW LEAKED

これが私のコードです親切に誰かが私が間違っていることを教えてください

public class Request_Movies_Conatiner_Activity_REQUESTS extends Activity implements  OnClickListener{

    String webrss, totalMovies;
    ProgressDialog dialog; 

    ListView RequestedMoviesListView;
    RequestMoviesCustomAdapter moviesCustomAdapter;
    ArrayList<RequestMovieListModel> adapters = new ArrayList<RequestMovieListModel>();

    LinearLayout requests_lineraLayout;

    Button first_page_button1_request, next_page_button1_request;

    TextView requests_textViewPages;
    int t,set=1;//for navigation purposes
    /** Called when the activity is first created. */
    int tab=1, b;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.request_list_layout_requests);


        RequestedMoviesListView = (ListView)findViewById(R.id.requests_listView);
        RequestedMoviesListView.setFastScrollEnabled(true);

        requests_lineraLayout = (LinearLayout)findViewById(R.id.request_linearLayout1);


        first_page_button1_request = (Button)findViewById(R.id.first_page_button1_request);
        next_page_button1_request = (Button)findViewById(R.id.next_page_button1_request);
        first_page_button1_request.setOnClickListener(this);
        next_page_button1_request.setOnClickListener(this);

        requests_textViewPages = (TextView)findViewById(R.id.requests_textViewPages);

        webrss = getString( R.string.requested_movies);
        Toast.makeText(getApplicationContext(), webrss, 1).show();
        adapters.clear();
        moviesCustomAdapter = new RequestMoviesCustomAdapter(Request_Movies_Conatiner_Activity_REQUESTS.this, R.layout.show_categories_list, adapters);
        moviesCustomAdapter.clear();
        dialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
        Thread thread=new Thread(new Runnable(){
            public void run(){
                MovieRequests();
                runOnUiThread(new Runnable(){
                    public void run() {
                        if(dialog.isShowing()){         
                            RequestedMoviesListView.setAdapter( moviesCustomAdapter );
                            dialog.dismiss();
                            MovieCount();
                        }
                    }
                });
            }
        });
        thread.start();
    }

    private void MovieCount() {
        try {
            URL yify = new URL(webrss);
            URLConnection tc = yify.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    tc.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                JSONObject jsonObject = new JSONObject(line);
                totalMovies = jsonObject.getString("MovieCount");
                int a = Integer.parseInt(totalMovies);
                t = (a/15)+1;

                requests_lineraLayout.setVisibility(View.VISIBLE);

                if (set == 1) {
                    requests_textViewPages.setText("1 of "+Integer.toString(t));
                }
                else{
                    requests_textViewPages.setText(set+" of "+Integer.toString(t));
                }

            }
        } catch (final MalformedURLException e) {
            // TODO Auto-generated catch block
            runOnUiThread(new Runnable(){
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
            });
            e.printStackTrace();
        } catch (final IOException e) {
            runOnUiThread(new Runnable(){
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
            });
            e.printStackTrace();
        } catch (final JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            runOnUiThread(new Runnable(){
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), e.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
            });
        }
    }

    private void MovieRequests() {
        try {   
            URL yify = new URL(webrss+"&set="+set);
            URLConnection tc = yify.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    tc.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {

                JSONObject jsonObject = new JSONObject(line);
                JSONArray ja = new JSONArray(jsonObject.getString("RequestList"));

                for (int i = 0; i < ja.length(); i++) {
                    JSONObject jo = (JSONObject) ja.get(i);
                    if (jo.has("error")) {
                        Toast.makeText(getApplicationContext(), jo.getString("error"), Toast.LENGTH_LONG).show();
                    }
                    else{
                        String request_id = jo.getString("RequestID");
                        String m_title = jo.getString("MovieTitle");
                        String imdb_url = jo.getString("ImdbLink");
                        String m_cover = jo.getString("CoverImage");
                        String short_description = jo.getString("ShortDescription");

                        String genere = jo.getString("Genre");
                        String imdb_rating = jo.getString("MovieRating");
                        String date_added = jo.getString("DateAdded");

                        String votes = jo.getString("Votes");
                        String requester_user_id = jo.getString("UserID");
                        String requester_user_name = jo.getString("Username");


                        RequestMovieListModel request_movies = new RequestMovieListModel(request_id, m_title, imdb_url, m_cover, short_description
                                ,genere, imdb_rating, date_added, votes, requester_user_id, requester_user_name);
                        // Process a newly found station
                        moviesCustomAdapter.add(request_movies);                        
                    }
                }
            }
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.first_page_button1_request:
            if (set ==1) {
                moviesCustomAdapter.clear();
                dialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
                Thread thread=new Thread(new Runnable(){
                    public void run(){
                        MovieRequests();
                        runOnUiThread(new Runnable(){
                            public void run() {
                                if(dialog.isShowing()){         
                                    RequestedMoviesListView.setAdapter( moviesCustomAdapter );
                                    dialog.dismiss();
                                    MovieCount();
                                }
                            }
                        });
                    }
                });
                thread.start();
            }
            else{
                set = set-1;
                moviesCustomAdapter.clear();
                dialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
                Thread thread=new Thread(new Runnable(){
                    public void run(){
                        MovieRequests();
                        runOnUiThread(new Runnable(){
                            public void run() {
                                if(dialog.isShowing()){         
                                    RequestedMoviesListView.setAdapter( moviesCustomAdapter );
                                    dialog.dismiss();
                                    MovieCount();
                                }
                            }
                        });
                    }
                });
                thread.start();
            }
            break;
        case R.id.next_page_button1_request:
            set = set+1;
            moviesCustomAdapter.clear();
            dialog = ProgressDialog.show(this, "", "Loading. Please wait...", true);
            Thread thread1=new Thread(new Runnable(){
                public void run(){
                    MovieRequests();
                    runOnUiThread(new Runnable(){
                        public void run() {
                            if(dialog.isShowing()){         
                                RequestedMoviesListView.setAdapter( moviesCustomAdapter );
                                dialog.dismiss();
                                MovieCount();
                            }
                        }
                    });
                }
            });
            thread1.start();
            break;
        default:
            break;
        }
    }
}

06-19 18:59:37.319: ERROR/WindowManager(14174): Activity androlizer.yify.torrent.Request_Movies_Conatiner_Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2bec3268 that was originally added here
06-19 18:59:37.319: ERROR/WindowManager(14174): android.view.WindowLeaked: Activity androlizer.yify.torrent.Request_Movies_Conatiner_Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2bec3268 that was originally added here
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:344)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:267)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.view.Window$LocalWindowManager.addView(Window.java:537)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.app.Dialog.show(Dialog.java:278)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.app.ProgressDialog.show(ProgressDialog.java:116)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.app.ProgressDialog.show(ProgressDialog.java:99)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at androlizer.yify.torrent.Request_Movies_Conatiner_Activity_REQUESTS.onClick(Request_Movies_Conatiner_Activity_REQUESTS.java:239)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.view.View.performClick(View.java:3534)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.view.View$PerformClick.run(View.java:14263)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.os.Handler.handleCallback(Handler.java:605)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.os.Looper.loop(Looper.java:137)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at android.app.ActivityThread.main(ActivityThread.java:4441)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at java.lang.reflect.Method.invokeNative(Native Method)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at java.lang.reflect.Method.invoke(Method.java:511)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-19 18:59:37.319: ERROR/WindowManager(14174):     at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1