2

我想将 MUPDF 源添加到我的项目并在我的应用程序上显示 pdf。

我在下面的链接中执行所有这些步骤

 http://mupdf.blogspot.com/

在将类添加到项目中之后,就像写在这里

 http://pastebin.com/YzHUhzE7

现在我想在我的应用程序的活动中显示一个 pdf 文件

    Uri uri = Uri.parse("/storage/sdcard0/A.pdf");

    Intent intent = new Intent(this, MuPDFActivity.class);

    intent.setAction(Intent.ACTION_VIEW);

    intent.setData(uri);

    this.startActivity(intent);

但我从 LogCat 得到这些错误

     06-27 16:14:12.872: E/AndroidRuntime(13161): FATAL EXCEPTION: main
     06-27 16:14:12.872: E/AndroidRuntime(13161): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.andpdfviewer/com.example.andpdfviewer.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.andpdfviewer/com.artifex.mupdfdemo.MuPDFActivity}; have you declared this activity in your AndroidManifest.xml?
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.ActivityThread.access$700(ActivityThread.java:140)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.os.Handler.dispatchMessage(Handler.java:99)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.os.Looper.loop(Looper.java:137)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.ActivityThread.main(ActivityThread.java:4921)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at java.lang.reflect.Method.invokeNative(Native Method)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at java.lang.reflect.Method.invoke(Method.java:511)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at dalvik.system.NativeStart.main(Native Method)
     06-27 16:14:12.872: E/AndroidRuntime(13161): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.andpdfviewer/com.artifex.mupdfdemo.MuPDFActivity}; have you declared this activity in your AndroidManifest.xml?
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1556)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1431)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Activity.startActivityForResult(Activity.java:3428)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Activity.startActivityForResult(Activity.java:3389)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Activity.startActivity(Activity.java:3599)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Activity.startActivity(Activity.java:3567)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at com.example.andpdfviewer.MainActivity.onCreate(MainActivity.java:26)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Activity.performCreate(Activity.java:5188)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
     06-27 16:14:12.872: E/AndroidRuntime(13161):   ... 11 more

这是我应用的 AndroidManifest.xml 标签:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.andpdfviewer.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name="com.artifex.mupdf.MuPDFActivity"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/vnd.ms-xpsdocument"/>
        </intent-filter>
        <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:mimeType="application/x-cbz"/>
        </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="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.xps"/>
            <data android:host="*"/>
        </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="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.pdf"/>
            <data android:host="*"/>
        </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="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.cbz"/>
            <data android:host="*"/>
        </intent-filter>
    </activity>
    <activity android:name="OutlineActivity"
              android:label="@string/outline_title">
    </activity>
</application>

可能是什么问题?我该如何解决?

4

1 回答 1

2
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.andpdfviewer/com.artifex.mupdfdemo.MuPDFActivity}; have you declared this activity in your AndroidManifest.xml?

仔细检查清单文件并将其声明为活动/修复它。

于 2013-06-27T13:25:20.690 回答