【发布时间】:2021-11-30 01:11:47
【问题描述】:
我已经构建了一个 PDF 阅读器,我想从手机 Ex 的任何地方打开 pdf。 Whatsapp,文件管理器。
当我从谷歌文件管理器打开 pdf 时它正在工作,当我从默认文件管理器打开它时它会崩溃
显示此错误
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.os.Bundle.get(java.lang.String)' on a null object reference
应用清单文件
<activity
android:name=".PDF_Viewer"
android:exported="true">
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<data
android:scheme="file"
android:host="*"
android:pathPattern=".*\.pdf" />
</intent-filter>
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<category
android:name="android.intent.category.DEFAULT" />
<category
android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="http"
android:host="*"
android:pathPattern=".*\.pdf" />
<data
android:scheme="https"
android:host="*"
android:pathPattern=".*\.pdf" />
</intent-filter>
</activity>
我在 PDF 查看器活动中收到这样的意图:
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
Uri pdf = (Uri) bundle.get(Intent.EXTRA_STREAM);
【问题讨论】:
-
发布更多代码,因为这个包来自某个地方。您的 NullPointerException 告诉 bundle==null。使用前检查是否为空。
-
我添加了更多代码,请检查
-
您没有在使用前添加代码来检查是否为空。此外,您没有提供额外信息。你现在会做什么 bundle==null ?
-
我不会在使用前检查捆绑包是否为空,如果您知道如何修复它,请帮助 -@blackapps
-
使用前检查bundle是否为空!添加代码!我第三次问了。
标签: android pdf android-intent android-pendingintent intentfilter