2012-06-22 37 views
1

我試圖打開我的gallary並在我的SD卡中選擇一個圖像,但它給我一個強制關閉錯誤,當我單擊按鈕打開一個gallary時,這裏是我的代碼在模擬器中打開gallary時強制關閉

public void openGallery(int req_code){ 

     Intent intent = new Intent(); 
     intent.setType("image/*"); 
     intent.setAction(Intent.ACTION_GET_CONTENT); 
     startActivityForResult(Intent.createChooser(intent,"Select file to upload "), req_code); 
    } 

這裏我的錯誤 力close..The應用相機

enter image description here

LOG貓

06-22 15:03:27.511: D/dalvikvm(179): GC_EXPLICIT freed <1K, 6% free 6439K/6791K, paused 6ms+6ms 
06-22 15:03:28.893: I/Process(13882): Sending signal. PID: 13882 SIG: 9 
06-22 15:03:29.041: W/InputManagerService(80): Window already focused, ignoring focus gain of: [email protected] 
06-22 15:03:30.121: I/ActivityManager(80): Process com.android.gallery (pid 13882) has died. 
06-22 15:03:30.121: W/WindowManager(80): Failure taking screenshot for (230x143) to layer 21015 
06-22 15:03:30.765: I/ActivityManager(80): Starting: Intent { act=android.intent.action.PICK dat=content://media/external/images/media cmp=com.android.gallery/com.android.camera.ImageGallery } from pid 13692 
06-22 15:03:30.771: W/WindowManager(80): Failure taking screenshot for (230x143) to layer 21015 
06-22 15:03:30.878: I/ActivityManager(80): Start proc com.android.gallery for activity com.android.gallery/com.android.camera.ImageGallery: pid=13920 uid=10017 gids={1015, 1024, 1006, 2001, 3003} 
06-22 15:03:32.221: W/ActivityManager(80): Activity destroy timeout for ActivityRecord{40e28e70 com.android.gallery/com.android.camera.ImageGallery} 
06-22 15:03:33.151: D/AndroidRuntime(13920): Shutting down VM 
06-22 15:03:33.151: W/dalvikvm(13920): threadid=1: thread exiting with uncaught exception (group=0x40014760) 
06-22 15:03:33.241: E/AndroidRuntime(13920): FATAL EXCEPTION: main 
06-22 15:03:33.241: E/AndroidRuntime(13920): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.gallery/com.android.camera.ImageGallery}: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.ActivityThread.access$1500(ActivityThread.java:122) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.os.Handler.dispatchMessage(Handler.java:99) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.os.Looper.loop(Looper.java:132) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.ActivityThread.main(ActivityThread.java:4025) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at java.lang.reflect.Method.invokeNative(Native Method) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at java.lang.reflect.Method.invoke(Method.java:491) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at dalvik.system.NativeStart.main(Native Method) 
06-22 15:03:33.241: E/AndroidRuntime(13920): Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features 
06-22 15:03:33.241: E/AndroidRuntime(13920): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:204) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2339) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2546) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:219) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.Activity.setContentView(Activity.java:1780) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at com.android.camera.ImageGallery.onCreate(ImageGallery.java:113) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 
06-22 15:03:33.241: E/AndroidRuntime(13920): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712) 
06-22 15:03:33.241: E/AndroidRuntime(13920): ... 11 more 
06-22 15:03:33.311: W/ActivityManager(80): Force finishing activity com.android.gallery/com.android.camera.ImageGallery 
06-22 15:03:33.401: W/WindowManager(80): Failure taking screenshot for (230x143) to layer 21020 
+1

發佈logcat錯誤。 – user370305

+0

粘貼你的logcat異常 –

+0

上面的代碼是完美的!發佈您的完整代碼和Logcat –

回答

0

使用此代碼,

Intent i = new Intent(Intent.ACTION_PICK, 
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    startActivityForResult(i,REQUEST_CODE); 
+1

仍然同樣的錯誤...強制關閉應用程序相機 – Zamani

0

使用此:

Intent i = new Intent(Intent.ACTION_PICK, 
      android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
startActivityForResult(i, ACTIVITY_SELECT_IMAGE); 

然後在onActivityForResult,調用intent.getData()來獲取圖像的URI。然後你需要從ContentProvider獲取圖像。

+0

可以請你添加onActivityForResult示例還 –

+0

錯誤...強制關閉應用程序相機 – Zamani

+0

@AndroSelvaThats沒有會做詭計 –

0

使用:

button.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View arg) { 
      Intent i = new Intent(Intent.ACTION_PICK, 
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
      startActivityForResult(i, ACTIVITY_SELECT_IMAGE); 
     } 
    }); 

然後在onActivityResult()

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    switch (requestCode) { 
     case REQ_CODE_PICK_IMAGE: 
      if (resultCode == RESULT_OK) { 
       Uri selectedImage = data.getData(); 
       String[] filePathColumn = {MediaStore.Images.Media.DATA}; 

       Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
       cursor.moveToFirst(); 

       int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
       String filePath = cursor.getString(columnIndex); 
       cursor.close(); 
       // Bitmap yourSelectedImage = BitmapFactory.decodeFile(filePath); 
      } 
    } 
} 
+1

我無法打開我的Gallary當我點擊按鈕的意圖 – Zamani

+0

代碼是完美的工作 – Freni

+0

我使用的是模擬器 – Zamani

0

也許你在你的清單忘了呢?

<uses-permission android:name="android.permission.CAMERA" /> 
+0

坦克,但仍然是相同的錯誤 – Zamani

+0

@ user1469168你可以發佈你的整個logcat,在你原來的問題?這將幫助我們很好地跟蹤問題出在哪裏 – Bigflow

+0

我剛剛發佈了它 – Zamani