如何在qpdf阅读器应用程序开发中修复以下错误

时间:2012-08-19 19:15:02

标签: android

我正在尝试使用Qpdf JAR文件开发一个android pdf阅读器应用程序,他们给出了一个用于pdf查看和编辑的示例代码,我按照qpdf参考给出的程序,并相应地对我的应用程序进行了更改,但是当我在模拟器上运行这个应用程序时,它就会停止。以下是logcat消息,任何人都可以帮助我吗?

08-20 00:26:26.787: E/AndroidRuntime(669): FATAL EXCEPTION: main
08-20 00:26:26.787: E/AndroidRuntime(669): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pdfreader/com.pdfreader.SamplePDFViewer}: android.view.InflateException: Binary XML file line #7: Error inflating class com.qoppa.samples.viewer.QScrollView
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.os.Looper.loop(Looper.java:137)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-20 00:26:26.787: E/AndroidRuntime(669):  at java.lang.reflect.Method.invokeNative(Native Method)
08-20 00:26:26.787: E/AndroidRuntime(669):  at java.lang.reflect.Method.invoke(Method.java:511)
08-20 00:26:26.787: E/AndroidRuntime(669):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-20 00:26:26.787: E/AndroidRuntime(669):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-20 00:26:26.787: E/AndroidRuntime(669):  at dalvik.system.NativeStart.main(Native Method)
08-20 00:26:26.787: E/AndroidRuntime(669): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.qoppa.samples.viewer.QScrollView
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-20 00:26:26.787: E/AndroidRuntime(669):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.Activity.setContentView(Activity.java:1835)
08-20 00:26:26.787: E/AndroidRuntime(669):  at com.pdfreader.SamplePDFViewer.onCreate(SamplePDFViewer.java:30)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.Activity.performCreate(Activity.java:4465)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-20 00:26:26.787: E/AndroidRuntime(669):  ... 11 more
08-20 00:26:26.787: E/AndroidRuntime(669): Caused by: java.lang.ClassNotFoundException: com.qoppa.samples.viewer.QScrollView
08-20 00:26:26.787: E/AndroidRuntime(669):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
08-20 00:26:26.787: E/AndroidRuntime(669):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-20 00:26:26.787: E/AndroidRuntime(669):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
08-20 00:26:26.787: E/AndroidRuntime(669):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
08-20 00:26:26.787: E/AndroidRuntime(669):  ... 21 more

2 个答案:

答案 0 :(得分:1)

遇到并解决了这个问题。 这可能是由“main.xml”引起的,其中包含“com.qoppa.samples.viewer.QScrollView”。

    <com.qoppa.samples.viewer.QScrollView
        android:id="@+id/scrollview"
        android:layout_gravity="center"
        android:background="#FFEEEEEE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/pagepane"
            android:background="#FFEEEEEE"
            android:gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        </LinearLayout>
    </com.qoppa.samples.viewer.QScrollView>

您需要将其替换为您自己的类来修复它。 对我来说:

    <com.example.qiaoruntao.trypdf08.QScrollView
        android:id="@+id/scrollview"
        android:layout_gravity="center"
        android:background="#FFEEEEEE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/pagepane"
            android:background="#FFEEEEEE"
            android:gravity="center_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        </LinearLayout>
    </com.example.qiaoruntao.trypdf08.QScrollView>

答案 1 :(得分:0)

Caused by: java.lang.ClassNotFoundException: com.qoppa.samples.viewer.QScrollView 

您可能尚未在清单中声明QScrollView吗?

<activity android:name=".QScrollView"
          android:label="QScrollViewActivity"/>