在我的应用中,我想从图库中选择一张图片:
Intent pickPhoto = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(pickPhoto , 1);
但有时候Android的画廊会停止。查看未过滤的日志我有以下错误(注意:我的代码中没有错误,系统抛出它):
橙色:
07-09 09:28:09.993: W/dalvikvm(22510): VFY: unable to resolve static method 1391: Landroid/sec/multiwindow/MultiWindow;.createInstance (Landroid/app/Activity;)Landroid/sec/multiwindow/MultiWindow;
07-09 09:28:09.993: D/dalvikvm(22510): VFY: replacing opcode 0x71 at 0x001a
07-09 09:28:10.008: I/dalvikvm(22510): Could not find method android.sec.multiwindow.MultiWindow.createInstance, referenced from method com.sec.android.gallery3d.util.GalleryUtils.setMultiWindow
07-09 09:28:10.008: W/dalvikvm(22510): VFY: unable to resolve static method 1391: Landroid/sec/multiwindow/MultiWindow;.createInstance (Landroid/app/Activity;)Landroid/sec/multiwindow/MultiWindow;
07-09 09:28:10.008: D/dalvikvm(22510): VFY: replacing opcode 0x71 at 0x001a
07-09 09:28:10.024: W/System.err(22510): android.content.pm.PackageManager$NameNotFoundException: com.skp.tcloud.agent
07-09 09:28:10.024: W/System.err(22510): at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:102)
07-09 09:28:10.024: W/System.err(22510): at com.sec.android.gallery3d.tCloud.TCloudRefer.isTCloudAgentExist(TCloudRefer.java:39)
07-09 09:28:10.024: W/System.err(22510): at com.sec.android.gallery3d.util.GalleryFeature.checkUseTCloud(GalleryFeature.java:882)
07-09 09:28:10.024: W/System.err(22510): at com.sec.android.gallery3d.util.GalleryFeature.init(GalleryFeature.java:294)
07-09 09:28:10.024: W/System.err(22510): at com.sec.android.gallery3d.app.GalleryAppImpl.getDataManager(GalleryAppImpl.java:205)
07-09 09:28:10.024: W/System.err(22510): at com.sec.android.gallery3d.provider.GalleryProvider.onCreate(GalleryProvider.java:124)
07-09 09:28:10.024: W/System.err(22510): at android.content.ContentProvider.attachInfo(ContentProvider.java:1058)
07-09 09:28:10.024: W/System.err(22510): at android.app.ActivityThread.installProvider(ActivityThread.java:4981)
07-09 09:28:10.024: W/System.err(22510): at android.app.ActivityThread.installContentProviders(ActivityThread.java:4593)
07-09 09:28:10.024: W/System.err(22510): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4533)
07-09 09:28:10.024: W/System.err(22510): at android.app.ActivityThread.access$1400(ActivityThread.java:150)
07-09 09:28:10.024: W/System.err(22510): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
07-09 09:28:10.024: W/System.err(22510): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 09:28:10.024: W/System.err(22510): at android.os.Looper.loop(Looper.java:175)
07-09 09:28:10.024: W/System.err(22510): at android.app.ActivityThread.main(ActivityThread.java:5279)
07-09 09:28:10.024: W/System.err(22510): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 09:28:10.024: W/System.err(22510): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 09:28:10.024: W/System.err(22510): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-09 09:28:10.024: W/System.err(22510): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-09 09:28:10.024: W/System.err(22510): at dalvik.system.NativeStart.main(Native Method)
红色之后的一些日志行:
07-09 09:16:21.876: E/AndroidRuntime(20732): FATAL EXCEPTION: main
07-09 09:16:21.876: E/AndroidRuntime(20732): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sec.android.gallery3d/com.sec.android.gallery3d.app.Gallery}: java.lang.NullPointerException
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.ActivityThread.access$700(ActivityThread.java:150)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.os.Looper.loop(Looper.java:175)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.ActivityThread.main(ActivityThread.java:5279)
07-09 09:16:21.876: E/AndroidRuntime(20732): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 09:16:21.876: E/AndroidRuntime(20732): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
07-09 09:16:21.876: E/AndroidRuntime(20732): at dalvik.system.NativeStart.main(Native Method)
07-09 09:16:21.876: E/AndroidRuntime(20732): Caused by: java.lang.NullPointerException
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.sec.samsung.gallery.controller.StartGalleryViewCmd.processIntent(StartGalleryViewCmd.java:98)
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.sec.samsung.gallery.controller.StartGalleryViewCmd.execute(StartGalleryViewCmd.java:60)
07-09 09:16:21.876: E/AndroidRuntime(20732): at org.puremvc.java.core.Controller.executeCommand(Controller.java:138)
07-09 09:16:21.876: E/AndroidRuntime(20732): at org.puremvc.java.core.Controller$1.onNotification(Controller.java:174)
07-09 09:16:21.876: E/AndroidRuntime(20732): at org.puremvc.java.patterns.observer.Observer.notifyObserver(Observer.java:87)
07-09 09:16:21.876: E/AndroidRuntime(20732): at org.puremvc.java.core.View.notifyObservers(View.java:134)
07-09 09:16:21.876: E/AndroidRuntime(20732): at org.puremvc.java.patterns.facade.Facade.notifyObservers(Facade.java:376)
07-09 09:16:21.876: E/AndroidRuntime(20732): at org.puremvc.java.patterns.facade.Facade.sendNotification(Facade.java:336)
07-09 09:16:21.876: E/AndroidRuntime(20732): at org.puremvc.java.patterns.facade.Facade.sendNotification(Facade.java:350)
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.sec.android.gallery3d.app.Gallery.processIntent(Gallery.java:805)
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.sec.android.gallery3d.app.Gallery.startView(Gallery.java:776)
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.sec.android.gallery3d.app.Gallery.startView(Gallery.java:758)
07-09 09:16:21.876: E/AndroidRuntime(20732): at com.sec.android.gallery3d.app.Gallery.onCreate(Gallery.java:232)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.Activity.performCreate(Activity.java:5283)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
07-09 09:16:21.876: E/AndroidRuntime(20732): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
07-09 09:16:21.876: E/AndroidRuntime(20732): ... 11 more
为什么它会在80%的时间内发生?
答案 0 :(得分:1)
请尝试这种方式,希望这有助于您解决问题。
final private int PICK_IMAGE_USER_AVATAR = 1;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, ""), PICK_IMAGE_USER_AVATAR);