Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用mPdfViewer打开文件。fromFile(文件)显示一个空pdf_Java_Android_Pdf - Fatal编程技术网

Java 使用mPdfViewer打开文件。fromFile(文件)显示一个空pdf

Java 使用mPdfViewer打开文件。fromFile(文件)显示一个空pdf,java,android,pdf,Java,Android,Pdf,我在使用PDFViewer库打开文件时遇到问题 DocumentCreator类内部: 1.首先,我使用iText库创建文档,它工作得非常好,并将文档写入给定目录。 2.然后,我创建一个文件对象,用PDFViewer显示它 try { mDocument = new Document(); // new Document created String path = "/" + FirebaseAuth.getInstance().getCurrentUser().

我在使用PDFViewer库打开文件时遇到问题

DocumentCreator类内部: 1.首先,我使用iText库创建文档,它工作得非常好,并将文档写入给定目录。 2.然后,我创建一个文件对象,用PDFViewer显示它

try {
        mDocument = new Document(); // new Document created
        String path = "/" + FirebaseAuth.getInstance().getCurrentUser().getUid() + "-" + recipe.getTitle() + ".pdf";
        String fullPath = Environment.getExternalStorageDirectory() + "/recipes" + path;
        mPdfWriter = PdfWriter.getInstance(mDocument, new FileOutputStream(fullPath));
        doTheWriting(recipe, activity);
        Log.d("OK", "done");

        mMyRecipeFile = new File(fullPath);

    }
    catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
在同一个类(DocumentCreator)中,我为mMyRecipeFile创建了getter方法

public File getRecipeFile() {
    return mMyRecipeFile;
}
之后在DocumentTestFragment中, 我创建了名为mPdfView的PDFView,并尝试打开此文件

mPdfView.fromFile(mDocCreator.getRecipeFile());

问题是它显示的是一个空文档,这很奇怪,因为我打开了Android设备监视器,打开了给定的文件,但它不是空的

我发现了问题的原因。问题是我写了:

PdfView.fromFile(file) 
适当的形式是必要的

PdfView.fromFile(file).load();

它现在工作得很好。

Log.d(“确定”、“完成”)??你是舒尔吗?您甚至没有检查doTheWriting()的返回值。
(Environment.getExternalStorageDirectory()+“/recipes”+path)
您再次构建该路径:
String fullPath=Environment.getExternalStorageDirectory()+“/recipes”+path。编程不好。做一次。多用几次。是的,谢谢你。同意,这不是最好的节目。这只是一个测试,所以我可以看到问题出在哪里。doTheWriting()工作得非常好,文件被创建并写入。问题是pdf文件存在于给定的目录中,但当我创建文件对象时,它会显示空pdf。外部应用程序是否会显示您的pdf文件?是否可以使用pdf查看器显示其他pdf文件?