我正在尝试使用PDFTron的PDFNet Android SDK制作pdf云共享解决方案。
我在这里关注指南:
[PDFNet for Android:入门指南] [1]
我成功将PDF库添加到我的项目中,并且运行正常。但是,当我尝试使用上面指南中的“添加对注释,文本选择和表单填充的支持”部分中的步骤添加工具库时,应用程序崩溃并显示消息“不幸的是,部署PDF文档已停止”
主要是,我希望得到一些日志输出的帮助。我试过谷歌搜索没有成功,坦率地说,我无法理解任何一个:
08-05 11:54:08.555: D/ActivityThread(11108): setTargetHeapUtilization:0.25
08-05 11:54:08.555: D/ActivityThread(11108): setTargetHeapIdealFree:8388608
08-05 11:54:08.565: D/ActivityThread(11108): setTargetHeapConcurrentStart:2097152
08-05 11:54:10.157: W/dalvikvm(11108): VFY: unable to resolve static method 963: Lpdftron/PDF/PDFNet;.initialize (Landroid/content/Context;I)V
08-05 11:54:10.157: W/dalvikvm(11108): VFY: unable to resolve exception class 251 (Lpdftron/Common/PDFNetException;)
08-05 11:54:10.157: W/dalvikvm(11108): VFY: unable to find exception handler at addr 0x3c
08-05 11:54:10.157: W/dalvikvm(11108): VFY: rejected Lcom/pdftron/android/tutorial/pttest/PTTestActivity;.onCreate (Landroid/os/Bundle;)V
08-05 11:54:10.157: W/dalvikvm(11108): VFY: rejecting opcode 0x0d at 0x003c
08-05 11:54:10.157: W/dalvikvm(11108): VFY: rejected Lcom/pdftron/android/tutorial/pttest/PTTestActivity;.onCreate (Landroid/os/Bundle;)V
08-05 11:54:10.157: W/dalvikvm(11108): Verifier rejected class Lcom/pdftron/android/tutorial/pttest/PTTestActivity;
08-05 11:54:10.157: W/dalvikvm(11108): Class init failed in newInstance call (Lcom/pdftron/android/tutorial/pttest/PTTestActivity;)
08-05 11:54:10.157: W/dalvikvm(11108): threadid=1: thread exiting with uncaught exception (group=0x41696438)
08-05 11:54:10.177: E/AndroidRuntime(11108): FATAL EXCEPTION: main
08-05 11:54:10.177: E/AndroidRuntime(11108): java.lang.VerifyError: com/pdftron/android/tutorial/pttest/PTTestActivity
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.Class.newInstanceImpl(Native Method)
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.Class.newInstance(Class.java:1319)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.Instrumentation.newActivity(Instrumentation.java:1068)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2025)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.access$700(ActivityThread.java:143)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.os.Looper.loop(Looper.java:137)
08-05 11:54:10.177: E/AndroidRuntime(11108): at android.app.ActivityThread.main(ActivityThread.java:4967)
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 11:54:10.177: E/AndroidRuntime(11108): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 11:54:10.177: E/AndroidRuntime(11108): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1011)
08-05 11:54:10.177: E/AndroidRuntime(11108): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
08-05 11:54:10.177: E/AndroidRuntime(11108): at dalvik.system.NativeStart.main(Native Method)
我不确定它是否会有所帮助,但这是我的活动的代码:
package com.pdftron.android.tutorial.pttest;
import java.io.IOException;
import java.io.InputStream;
import pdftron.Common.PDFNetException;
import pdftron.PDF.PDFDoc;
import pdftron.PDF.PDFNet;
import pdftron.PDF.PDFViewCtrl;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
public class PTTestActivity extends Activity
{
private PDFViewCtrl mPDFViewCtrl;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Initialize the library
try
{
PDFNet.initialize(this, R.raw.pdfnet);
}
catch (PDFNetException e)
{
Log.e("test", "PDFNetException: Line 28");
}
// Inflate the view and get a reference to PDFViewCtrl
setContentView(R.layout.main);
mPDFViewCtrl = (PDFViewCtrl) findViewById(R.id.pdfviewctrl);
mPDFViewCtrl.setToolManager(new pdftron.PDF.Tools.ToolManager(mPDFViewCtrl));
// Load a document
PDFDoc doc = null;
Resources res = getResources();
InputStream is = res.openRawResource(R.raw.sample);
try
{
doc = new PDFDoc(is);
// Or you can use the full path instead
//doc = new PDFDoc("/mnt/sdcard/sample_doc.pdf");
}
catch (PDFNetException e)
{
doc = null;
Log.e("test", "PDFNetException: Line 50", e);
}
catch (IOException e)
{
doc = null;
Log.e("test", "IOException: Line 55", e);
}
try
{
mPDFViewCtrl.setDoc(doc);
}
catch (PDFNetException e)
{
Log.e("test", "PDFNetException: Line 65", e);
}
}
@Override
protected void onPause()
{
// This method simply stops the current ongoing rendering thread, text
// search thread, and tool
super.onPause();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.pause();
}
}
@Override
protected void onResume()
{
// This method simply starts the rendering thread to ensure the PDF
// content is available for viewing.
super.onResume();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.resume();
}
}
@Override
protected void onDestroy()
{
// Destroy PDFViewCtrl and clean up memory and used resources.
super.onDestroy();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.destroy();
}
}
@Override
public void onLowMemory()
{
// Call this method to lower PDFViewCtrl's memory consumption.
super.onLowMemory();
if (mPDFViewCtrl != null)
{
mPDFViewCtrl.purgeMemory();
}
}
}
这是我的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pdftron.android.tutorial.pttest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" />
<application android:icon="@drawable/rollout" android:label="@string/app_name"
android:theme="@style/AppTheme" android:hardwareAccelerated="true" >
<activity android:name="PTTestActivity" android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
就像我说的,我主要想要一些解释或澄清日志输出。我已经为我的代码抛出并捕获的任何异常做了一个过滤器,但没有显示出来。
答案 0 :(得分:0)
要确保的一件事是,您在自己的项目中使用Tool的项目,并且PDFNet.jar位于Tool的项目中。此外,您可能需要检查PDFNet SDK(.so文件,PDFNet.jar,工具项目本身)的文件之间是否存在版本不匹配,因为您看到的错误可能表明这些文件之间的版本不匹配