0

我已经获取并保存了存储在图库中的图像的 uri,然后我想再次使用图库打开该图像。

我正在使用这个意图......但我得到空指针......

public void vedifoto(View view) {
    int i = mViewPager.getCurrentItem();
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse(foto[i]), "image/*");
    startActivity(intent);
}

错误堆栈:

08-12 09:33:35.669: E/AndroidRuntime(1012): FATAL EXCEPTION: main
08-12 09:33:35.669: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start    activity ComponentInfo{com.android.gallery/com.android.camera.ViewImage}: java.lang.NullPointerException
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.os.Looper.loop(Looper.java:137)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.main(ActivityThread.java:5041)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at java.lang.reflect.Method.invokeNative(Native Method)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at java.lang.reflect.Method.invoke(Method.java:511)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at dalvik.system.NativeStart.main(Native Method)
08-12 09:33:35.669: E/AndroidRuntime(1012): Caused by: java.lang.NullPointerException
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.camera.MenuHelper.isWhiteListUri(MenuHelper.java:151)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at com.android.camera.ViewImage.onCreate(ViewImage.java:617)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.Activity.performCreate(Activity.java:5104)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
08-12 09:33:35.669: E/AndroidRuntime(1012):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
08-12 09:33:35.669: E/AndroidRuntime(1012):     ... 11 more

foto 是我的照片在图库中的路径,我将其用作按钮图像,并且它可以工作,当用户单击它时,我需要在图库中查看该图像。

4

1 回答 1

0

使用此代码

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

您需要指定正确的路径...

于 2013-08-12T09:42:01.887 回答