2013-03-13 29 views
-2

我是新的android和我已经分配了一个项目。我遇到问题,通过错误日志时发现问题。这里是我的错误日志请告诉我这是什么问题以及它如何能够得到解决如何知道在Android编码问题在哪里

03-13 12:40:06.470: E/WindowManager(923): android.view.WindowLeaked: Activity om.example.mytest.ReadContactsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d0e768 V.E..... R.....ID 0,0-97,92} that was originally added here 
03-13 12:40:06.470: E/WindowManager(923): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354) 
03-13 12:40:06.470: E/WindowManager(923): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216) 
03-13 12:40:06.470: E/WindowManager(923): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.Dialog.show(Dialog.java:281) 
03-13 12:40:06.470: E/WindowManager(923): at com.example.mytest.ReadContactsActivity$CountDownTask.onPreExecute(ReadContactsActivity.java:50) 
03-13 12:40:06.470: E/WindowManager(923): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586) 
03-13 12:40:06.470: E/WindowManager(923): at android.os.AsyncTask.execute(AsyncTask.java:534) 
03-13 12:40:06.470: E/WindowManager(923): at com.example.mytest.ReadContactsActivity.onCreate(ReadContactsActivity.java:34) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.Activity.performCreate(Activity.java:5104) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.ActivityThread.access$600(ActivityThread.java:141) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
03-13 12:40:06.470: E/WindowManager(923): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-13 12:40:06.470: E/WindowManager(923): at android.os.Looper.loop(Looper.java:137) 
03-13 12:40:06.470: E/WindowManager(923): at android.app.ActivityThread.main(ActivityThread.java:5039) 
03-13 12:40:06.470: E/WindowManager(923): at java.lang.reflect.Method.invokeNative(Native Method) 
03-13 12:40:06.470: E/WindowManager(923): at java.lang.reflect.Method.invoke(Method.java:511) 
03-13 12:40:06.470: E/WindowManager(923): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
03-13 12:40:06.470: E/WindowManager(923): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
03-13 12:40:06.470: E/WindowManager(923): at dalvik.system.NativeStart.main(Native Method) 

这里是我写的代码来实现

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


    // A callback method executed on UI thread on starting the task 
    @Override 
    protected void onPreExecute() { 
     // Getting reference to the TextView tv_counter of the layout activity_main 
     dialog = new Dialog(ReadContactsActivity.this); 
     dialog.setCancelable(false); 
     dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     dialog.setContentView(R.layout.progressdialog); 

     progressBar = (ProgressBar) dialog.findViewById(R.id.progressBar1); 
     dialog.show(); 


    } 

    // A callback method executed on non UI thread, invoked after 
    // onPreExecute method if exists 

    protected Void doInBackground(Void... params) { 
     ContentResolver cr = ReadContactsActivity.this.getContentResolver(); 
     Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, 
       null, null, null, null); 

     if (cur.getCount() > 0) { 
      while (cur.moveToNext()) { 
       String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); 
       String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
       if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) { 
        Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null, 
              ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", 
              new String[]{id}, null); 
        while (pCur.moveToNext()) { 
          String phone = pCur.getString(
            pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); 
          objItem = new listBean(); 
         objItem.setName(name); 
         objItem.setNumber(phone); 
         listArray.add(objItem); 
        } 
        pCur.close(); 
        } 
       } 
      } 
     return null; 
    } 


    // A callback method executed on UI thread, invoked by the publishProgress() 
    // from doInBackground() method 
    @Override 
    protected void onProgressUpdate(String... values) { 

    } 


    @Override 
    protected void onPostExecute(Void result) { 
     dialog.dismiss(); 
     objAdapter = new listAdapter(ReadContactsActivity.this, items); 
     listView.setAdapter(objAdapter); 

     } 
+1

你应该看看代码第一或使用魔法宝珠...... – Selvin 2013-03-13 12:48:31

+1

安置自己的代码.. – Subburaj 2013-03-13 12:48:36

+1

请检查此行。在com.example.mytest.ReadContactsActivity $ CountDownTask.onPreExecute(ReadContactsActivity.java:50) – 2013-03-13 12:49:03

回答

1

如何知道采用的是Android编码的问题?

您始终与行数 logcat中找到你的活动名称如果在您的活动代码中的错误。

1

不要在主线程上编写解除对话框的代码。保持它runOnUIThread如下:

@Override 
    protected void onPostExecute(Void result) { 
     runOnUiThread(new Runnable() { 
       @Override 
       public void run() { 
         dialog.dismiss(); 
      } 
    objAdapter = new listAdapter(ReadContactsActivity.this, items); 
    listView.setAdapter(objAdapter); 
    }