2012-12-18 58 views
0

嗨我有下面的代碼讓使用捕獲圖像或從畫廊中選擇它。我捕獲一個圖像保存它,然後嘗試從圖庫中選擇圖片應用程序總是崩潰。相機和畫廊在Android崩潰畫廊應用程序使用

AlertDialog.Builder photoDialog = new AlertDialog.Builder(this); 
     photoDialog 
     .setTitle("Photo source") 
     .setCancelable(true) 
     .setPositiveButton("Open Gallery", 
     new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, 
          int id) { 
           startActivityForResult(
             new Intent(     Intent.ACTION_PICK,            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI), 
             54); 
} 
}) 
.setNegativeButton("Open Camera", 
new DialogInterface.OnClickListener() { 
    public void onClick(DialogInterface dialog, 
        int id) { 
     String fileName = "temp.jpg"; 
     ContentValues values = new ContentValues(); 
     values.put(MediaStore.Images.Media.TITLE, 
      fileName); 
     mCapturedImageURI = getContentResolver() 
      .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,          values); 
     Intent intent = new Intent(        MediaStore.ACTION_IMAGE_CAPTURE); 
     intent.putExtra(MediaStore.EXTRA_OUTPUT,         mCapturedImageURI); 

           startActivityForResult(intent, 96); 

          } 
         }); 
     photoDialog.show(); 

日誌

I/ActivityManager( 222): Starting: Intent { act=android.intent.action.PICK dat=content://media/external/images/media cmp=com.cooliris.media/.Gallery } from pid 13631 

I/SiteInspection(13631): In SiteInspectionDetailsActivity.onSaveInstanceState() ....... 

I/ActivityManager( 222): Start proc com.cooliris.media for activity com.cooliris.media/.Gallery: pid=13685 uid=10028 gids={1015, 3003} 

W/InputManagerService( 222): Window already focused, ignoring focus gain of: [email protected] 

D/BackgroundDataSender(13631): BackgroundDataService started 

D/BackgroundLogSender(13631): BackgroundLogService started 

D/BackgroundLogSender(13631): true 

D/BackgroundLogSender(13631): logsender ted 

I/ActivityThread(13685): Pub com.cooliris.picasa.contentprovider: com.cooliris.picasa.PicasaContentProvider 

I/Gallery (13685): onCreate 

D/CacheService(13685): Refreshing Cache for all items 

I/CacheService(13685): Refreshing cache. 

E/DiskCache(13685): Unable to create or tempFile /mnt/sdcard/Android/data/com.cooliris.media/cache/local-album-cache 

I/CacheService(13685): Building albums. 

I/ActivityManager( 222): Displayed com.cooliris.media/.Gallery: +659ms 

E/DiskCache(13685): Unable to create or tempFile /mnt/sdcard/Android/data/com.cooliris.media/cache/local-album-cache 

I/CacheService(13685): Done building albums. 

I/CacheService(13685): Building items. 

E/DiskCache(13685): Unable to create or tempFile /mnt/sdcard/Android/data/com.cooliris.media/cache/local-album-cache 

I/CacheService(13685): Done building items. 

I/RenderView(13685): First Draw 

I/MediaFeed(13685): Replacing media set -1595679508 

I/MediaFeed(13685): Replacing media set 1506676782 

D/CacheService(13685): Refreshing Cache for all items 

I/CacheService(13685): Refreshing cache. 

E/DiskCache(13685): Unable to create or tempFile /mnt/sdcard/Android/data/com.cooliris.media/cache/local-album-cache 

I/CacheService(13685): Building albums. 

W/IInputConnectionWrapper(13631): showStatusIcon on inactive InputConnection 

E/DiskCache(13685): Unable to create or tempFile /mnt/sdcard/Android/data/com.cooliris.media/cache/local-album-cache 

I/CacheService(13685): Done building albums. 

I/CacheService(13685): Building items. 

D/BackgroundDataSender(13631): BackgroundDataService started 

D/BackgroundLogSender(13631): BackgroundLogService started 

D/BackgroundLogSender(13631): true 

D/BackgroundLogSender(13631): logsender ted 

E/DiskCache(13685): Unable to create or tempFile /mnt/sdcard/Android/data/com.cooliris.media/cache/local-album-cache 

I/CacheService(13685): Done building items. 

I/GridLayer(13685): Slot changing from -1 to -1 

D/BackgroundDataSender(13631): BackgroundDataService started 

D/BackgroundLogSender(13631): BackgroundLogService started 

D/BackgroundLogSender(13631): true 

D/BackgroundLogSender(13631): logsender ted 

D/BackgroundDataSender(13631): BackgroundDataService started 

D/BackgroundLogSender(13631): BackgroundLogService started 

D/BackgroundLogSender(13631): true 

D/BackgroundLogSender(13631): logsender ted 

D/wpa_supplicant( 456): wpa_supplicant_scan: scan_req = 0, ap_scan = 1 

D/wpa_supplicant( 456): Starting AP scan (broadcast SSID) 

D/wpa_supplicant( 456): wpa_driver_wext_scan: specific scan = 0 

D/wpa_supplicant( 456): Scan requested (ret=0) - scan timeout 30 seconds 

I/GridLayer(13685): Slot changing from 0 to 0 

I/RenderView(13685): Texture creation fail, glError 1281 

D/BackgroundDataSender(13631): BackgroundDataService started 

D/BackgroundLogSender(13631): BackgroundLogService started 

D/BackgroundLogSender(13631): true 

D/BackgroundLogSender(13631): logsender ted 

I/CacheService(13685): Built thumbnail and screennail for 19 in 628 

W/dalvikvm(13685): threadid=11: thread exiting with uncaught exception (group=0x40015560) 

E/AndroidRuntime(13685): FATAL EXCEPTION: GLThread 13 

E/AndroidRuntime(13685): java.lang.NullPointerException 

E/AndroidRuntime(13685): at com.cooliris.media.GridDrawManager.drawBlendedComponents(GridDrawManager.java:716) 

E/AndroidRuntime(13685): at com.cooliris.media.GridLayer.renderBlended(GridLayer.java:831) 

E/AndroidRuntime(13685): at com.cooliris.media.RenderView.onDrawFrame(RenderView.java:684) 

E/AndroidRuntime(13685): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1363) 

E/AndroidRuntime(13685): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118) 

I/RenderView(13685): OnPause RenderView [email protected] 

W/ActivityManager( 222): Force finishing activity com.cooliris.media/.Gallery 
+0

您可以發佈您的logcat .. – Nermeen

+0

我已經發布了logcat的。我也試過boradcasting意圖Intent.ACTION_MEDIA_SCANNER_SCAN_FILE即使然後它崩潰 – user1059747

+0

問題在這裏:java.lang.NullPointerException在com.cooliris.media.GridDrawManager.drawBlendedComponents(GridDrawManager.java:716) – Nermeen

回答

0

使用此:

Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); 
photoPickerIntent.setType("image/*"); 
startActivityForResult(photoPickerIntent, SELECT_PHOTO); 

和onActivityResult:

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) { 
    case SELECT_PHOTO: 
     if(resultCode == getActivity().RESULT_OK){ 

      Uri picUri = imageReturnedIntent.getData(); 

     } 
     break; 
    } 
} 
+0

我接受了認爲它有效的答案。但它再次墜毀。這隻發生在2.3版Android手機上。 – user1059747

+0

在哪一點它崩潰? –

+0

同一點出現同樣的錯誤。我第一次捕捉圖像保存,然後嘗試從gallary中選擇一個圖像,它崩潰。 – user1059747