我想在我的应用程序中打开PDF文件..我已经在我的模拟器中安装了android pdf查看器..正在使用以下代码..“https://github.com/jesperborgstrup/buzzingandroid/blob/master/src/com/buzzingandroid/tools/PDFTools.java”
now i添加PDF文件在我的资产文件夹..这是我的代码..在Android应用程序中打开PDF文件
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button;
final String url = "android.resource://com.buzzingandroid.tools/raw/ll.pdf";
final PDFTools pdf = new PDFTools();
button = (Button)this.findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@SuppressWarnings("static-access")
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pdf.showPDFUrl(Context,url);
}
});
的“ispdfsupported”模块中的PRG崩溃。该模块如下..
public static boolean isPDFSupported(Context context) {
Intent i = new Intent(Intent.ACTION_VIEW);
final File tempFile = new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "test.pdf");
i.setDataAndType(Uri.fromFile(tempFile), PDF_MIME_TYPE);
return context.getPackageManager().queryIntentActivities(i, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}
和我的日志猫..
02-24 01:08:59.912: E/AndroidRuntime(1172): FATAL EXCEPTION: main
02-24 01:08:59.912: E/AndroidRuntime(1172): Process: com.buzzingandroid.tools, PID: 1172
02-24 01:08:59.912: E/AndroidRuntime(1172): java.lang.NullPointerException
02-24 01:08:59.912: E/AndroidRuntime(1172): at com.buzzingandroid.tools.PDFTools.isPDFSupported(PDFTools.java:142)
02-24 01:08:59.912: E/AndroidRuntime(1172): at com.buzzingandroid.tools.PDFTools.showPDFUrl(PDFTools.java:38)
02-24 01:08:59.912: E/AndroidRuntime(1172): at com.buzzingandroid.tools.MAIN$1.onClick(MAIN.java:30)
02-24 01:08:59.912: E/AndroidRuntime(1172): at android.view.View.performClick(View.java:4438)
02-24 01:08:59.912: E/AndroidRuntime(1172): at android.view.View$PerformClick.run(View.java:18422)
02-24 01:08:59.912: E/AndroidRuntime(1172): at android.os.Handler.handleCallback(Handler.java:733)
02-24 01:08:59.912: E/AndroidRuntime(1172): at android.os.Handler.dispatchMessage(Handler.java:95)
02-24 01:08:59.912: E/AndroidRuntime(1172): at android.os.Looper.loop(Looper.java:136)
02-24 01:08:59.912: E/AndroidRuntime(1172): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-24 01:08:59.912: E/AndroidRuntime(1172): at java.lang.reflect.Method.invokeNative(Native Method)
02-24 01:08:59.912: E/AndroidRuntime(1172): at java.lang.reflect.Method.invoke(Method.java:515)
02-24 01:08:59.912: E/AndroidRuntime(1172): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-24 01:08:59.912: E/AndroidRuntime(1172): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-24 01:08:59.912: E/AndroidRuntime(1172): at dalvik.system.NativeStart.main(Native Method)
请解释我做错了什么..在此先感谢..
还我已经给了一个网址从服务器访问PDF ..它坠毁在同一个地方..日志猫相同的错误...
张贴您的logcat。 –