java - 安卓 - PDF Int。 - 新实例失败 - 无法实例化

标签 java android pdf jar integrate

我已尝试集成此 PDF Viever,但收到此崩溃消息:

05-31 11:20:48.717: D/ddm-heap(235): Got feature list request

05-31 11:21:16.117: D/dalvikvm(235): newInstance failed: p0 i0 [0 a1

05-31 11:21:16.127: D/AndroidRuntime(235): Shutting down VM

05-31 11:21:16.127: W/dalvikvm(235): threadid=3: thread exiting with uncaught exception (group=0x4001b188)

05-31 11:21:16.127: E/AndroidRuntime(235): Uncaught handler: thread main exiting due to uncaught exception

05-31 11:21:16.137: E/AndroidRuntime(235): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.sf.andpdf.pdfviewer/net.sf.andpdf.pdfviewer.PdfViewerActivity}: 
java.lang.InstantiationException: net.sf.andpdf.pdfviewer.PdfViewerActivity

05-31 11:21:16.137: E/AndroidRuntime(235):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)

这就是我尝试实现的:https://github.com/jblough/Android-Pdf-Viewer-Library

集成 Activity 的帮助文本说:

1) Add PdfViewer.jar into your project's build path

2) Copy the following drawable resources from PdfViewer/res/drawable into YourProject/res/drawable
     left_arrow.png
     right_arrow.png
     zoom_in.png
     zoom_out.png

3) Copy the following layout resources from PdfViewer/res/layout into YourProject/res/layout
     dialog_pagenumber.xml
     pdf_file_password.xml

!!THIS IS WHERE THE PROBLEM LIES!! - SE BELOW

4) ***Derive your PDF activity from net.sf.andpdf.pdfviewer.PdfViewerActivity***

5) Using the default drawables and layouts:
     public int getPreviousPageImageResource() { return R.drawable.left_arrow; }
     public int getNextPageImageResource() { return R.drawable.right_arrow; }
     public int getZoomInImageResource() { return R.drawable.zoom_in; }
     public int getZoomOutImageResource() { return R.drawable.zoom_out; }
     public int getPdfPasswordLayoutResource() { return R.layout.pdf_file_password; }
     public int getPdfPageNumberResource() { return R.layout.dialog_pagenumber; }
     public int getPdfPasswordEditField() { return R.id.etPassword; }
     public int getPdfPasswordOkButton() { return R.id.btOK; }
     public int getPdfPasswordExitButton() { return R.id.btExit; }
     public int getPdfPageNumberEditField() { return R.id.pagenum_edit; }

6) Invoke your PdfViewActivity derived with the following code:
     Intent intent = new Intent(this, YourPdfViewerActivity.class);
     intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE");
     startActivity(intent);

我已经尝试将 pdfviewer Activity .jar 集成为外部 JAR 或在 Assets 文件夹中实现它并从那里加载 Jar。 PdfViewer Activity 位于 src 类文件夹 (sf.net.andpdf.....) 中,我也将其命名为 100%,就像代码是“创建的”一样。

list :

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".Niels"
        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=".PdfViewerActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.PDFVIEWERACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
     </activity>        
    <activity android:name=".PdfViewerActivity" />               
</application>

尼尔斯.Java:

    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1 : 

            try{    
        Intent intent = new Intent(this, PdfViewerActivity.class /*i called this without "Your" as the actual class is named without "Your"*/ );
         intent.putExtra(net.sf.andpdf.pdfviewer.PdfViewerActivity.EXTRA_PDFFILENAME, "R.drawable.untitled" /*-> untitled.pdf*/);
         startActivity(intent); }
            catch (Exception e){                        
            e.printStackTrace();
            }

那么我做错了什么有什么想法吗?

最佳答案

好的,问题是缺少 pdfactivity 的实例化。

我创建了新类:

PDF阅读器.java :

package net.sf.andpdf.pdfviewer;

public class PdfReader extends PdfViewerActivity {
@Override
public int getPreviousPageImageResource() {
    // TODO Auto-generated method stub
    return 0;
}

因此我更改了此部分:

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button1 : 
        try {   
            Intent intent = new Intent(this, PdfReader.class /*the name changed*/);
            intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "R.drawable.untitled");
            startActivity(intent); 
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

最后我也将新 Activity 添加到 list 中。

这解决了这个问题,但我遇到了“无法解析父类(super class)”的新问题 - 这是一个新问题。

关于java - 安卓 - PDF Int。 - 新实例失败 - 无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10832720/

相关文章:

java - 如何检查Android中特定网络的数据消耗

javascript - 如何检测 PDF 数据对象是否在 html 对象中加载/播放/有效

java - 当现有 PDF 文档中页面旋转为空时该怎么办?

php - 如何使用中文版 mPDF

java - Java 代码测试中的说明

android - 在 Configuration Activity 中创建 Widget 的 "Preview"

java - 用 vector 投影找点

android - 无法解析 API 文件 "frameworks/base/api/current.txt"

java - 如何使用 Guice 3.0 为 JSP 提供服务?

java - 将图像和背景添加到 NatTable 行