gpt4 book ai didi

Android - 图库应用程序 NullPointerException - OnePlus One

转载 作者:行者123 更新时间:2023-11-30 00:48:55 25 4
gpt4 key购买 nike

我正在使用此代码通过我的应用程序打开图库应用程序 -

Intent galleryIntent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
galleryIntent.setType("image/*");
startActivity(galleryIntent);

当我选择“使用图库打开”时,图库应用程序在 OnePlus One 设备上崩溃并显示此堆栈跟踪 -

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cyngn.gallerynext/com.cyngn.gallerynext.app.fullscreenviewer.FullscreenViewer}: java.lang.NullPointerException: uriString
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
at android.app.ActivityThread.access$900(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
Caused by: java.lang.NullPointerException: uriString
at android.net.Uri$StringUri.<init>(Uri.java:470)
at android.net.Uri$StringUri.<init>(Uri.java:460)
at android.net.Uri.parse(Uri.java:432)
at com.cyngn.gallerynext.app.fullscreenviewer.FullscreenViewer.a(SourceFile:305)
at com.cyngn.gallerynext.app.fullscreenviewer.FullscreenViewer.onCreate(SourceFile:217)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420) 
at android.app.ActivityThread.access$900(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5292) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 

我不想将特定的 URI 传递给它,我只想让它打开默认的图库文件夹。我该如何避免这种崩溃?

最佳答案

不使用 setType("image/*")

Intent galleryIntent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivity(galleryIntent);

yourIntent.setType(String mimeType) 这表示您想要获取的 MIME 类型数据。使用 android.provider.MediaStore.Images.Media 你有不变的 MIME。我想,在这里你可以找到更多docs

关于Android - 图库应用程序 NullPointerException - OnePlus One,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41363039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com