2012-04-16 54 views
0

當我在應用程序中從圖庫中上傳圖像,但是當我選擇了一些圖像時,我得到了這個異常。從galleryActivity加載圖像時泄露了最初添加的窗口?

android.view.WindowLeaked: Activity has leaked window [email protected] that was originally added here 

android.view.WindowManagerImpl.addView(Win 

dowManagerImpl.java:152) 我沒有;噸爲什麼我得到異常隨機?

這個代碼是開放的畫廊..

Intent intent = new Intent(); 
     intent.setType("image/*"); 
     intent.setAction(Intent.ACTION_GET_CONTENT); 
     ((Activity) context).startActivityForResult(Intent.createChooser(intent,"Select Picture"), PICK_FROM_FILE); 

下面的代碼是從畫廊 得到的bimap我

f (resultCode == RESULT_OK) 
        { 

         Uri contentUri = data.getData(); 
         System.out.println("**************contentUri***************"+contentUri); 
         String[] proj = { MediaStore.Images.Media.DATA }; 
         Cursor cursor = managedQuery(contentUri, proj, null, null, null); 
         int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
         cursor.moveToFirst(); 
         String tmppath = cursor.getString(column_index); 
         // File abc= new File(tmppath); 
         System.out.println("**************tmppath***************"+tmppath); 

         Bitmap mBitmap = BitmapFactory.decodeFile(tmppath); 
         // Bitmap bitmap = BitmapFactory.decodeFile(abc); 
         System.out.println("**************mBitmap(gallery)***************"+mBitmap); 
         Court_formations objectdat =new Court_formations(); 
         objectdat.showGalleryimage(getDialogContext(),mBitmap); 

plz幫助

+0

你能不能粘貼你的代碼 – 2012-04-16 07:22:00

+0

當我在horizo​​nall模式下打開圖庫,然後回到應用程序,因爲它修復了potrait模式,然後我得到了這個異常 – user1287756 2012-04-16 07:30:44

+0

你只是從圖像中選取圖像並在imageview上顯示它? – 2012-04-16 07:37:11

回答

1

在onactivity結果,嘗試使用這些代碼:

Uri selectedImageUri = Uri.parse(data.getDataString()); 
ContentResolver cr = getContentResolver(); 
InputStream in = null; 
try { 
in = cr.openInputStream(selectedImageUri); 
} catch (FileNotFoundException e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} 
BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inSampleSize=20; 
Bitmap mBitmap = BitmapFactory.decodeStream(in,null,options); 
Court_formations objectdat =new Court_formations(); 
objectdat.showGalleryimage(getDialogContext(),mBitmap); 
+0

如果上述將解決您的問題,然後添加這些爲你的活動在清單文件.. android:configChanges =「keyboardHidden | orientation」 – 2012-04-16 07:51:20

+0

感謝它解決了問題 – user1287756 2012-04-16 08:08:31

+0

我有一個問題,我有一個圖像我得到了位圖= null .. – user1287756 2012-04-16 08:11:05

相關問題