错误活动已泄露窗口com.android.internal.policy.impl.PhoneWindow $ DecorView

时间:2015-03-18 18:26:27

标签: android

我正从表学生中检索数据(姓名,结果) 使用以下代码:

public class SelectActivity extends ActionBarActivity {

    JSONArray jsonArray = null;
    TextView tv_select;
    ProgressDialog pDialog;

    JSONParser jsonParser = new JSONParser();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);

        tv_select =(TextView)findViewById(R.id.tv_select);
         new LoadAllStudents().execute();

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_select, menu);
        return true;
    }

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

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(SelectActivity.this);
            pDialog.setMessage("Loading data. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            if(pDialog!=null)
            {
                pDialog.dismiss();
                pDialog =null;
            }
        }

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

           // List<NameValuePair> params = new ArrayList<NameValuePair>();
            JSONObject json = jsonParser.getJSONFromUrl(app_url);
            String studString ="";

            try {
                JSONArray student = json.getJSONArray("data");
                for (int i= 0;i<student.length();i++)
                {
                    JSONObject json1 =null;
                    try
                    {
                        json1 = student.getJSONObject(i);
                        studString = studString+
                        "Name"+ json1.getString("name")+"\n"+"Result"+json1.getString("result")+"\n";

                    }catch (JSONException e)
                    {
                        e.printStackTrace();
                    }

                }
tv_select.setText(studString);

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }


    }



    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}

未能发出以下错误:

SelectActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41914d60 V.E..... R......D 0,0-684,192} that was originally added here
    android.view.WindowLeaked: Activity com.example.shubham.helloworld.SelectActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41914d60 V.E..... R......D 0,0-684,192} that was originally added here
            at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
            at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
            at android.app.Dialog.show(Dialog.java:281)
            at com.example.shubham.helloworld.SelectActivity$LoadAllStudents.onPreExecute(SelectActivity.java:57)
            at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
            at android.os.AsyncTask.execute(AsyncTask.java:534)
            at com.example.shubham.helloworld.SelectActivity.onCreate(SelectActivity.java:35)
            at android.app.Activity.performCreate(Activity.java:5122)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
            at android.app.ActivityThread.access$600(ActivityThread.java:156)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:153)
            at android.app.ActivityThread.main(ActivityThread.java:5297)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案