公共课不公开?

时间:2017-02-15 13:14:27

标签: java android

我尝试使用此代码的部分内容:https://github.com/androidsrc/PdfReadWrite/tree/master/app

更确切地说,这部分:

   public class PdfGenerationTask extends AsyncTask<Void, Void,String>{

        protected String doInBackground(Void... params) {
            PdfDocument document = new PdfDocument();
            View author = findViewById(R.id.author);
            int pageNumber = 1;
            PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo().Builder(20,20,pageNumber).create();
            PdfDocument.Page page = document.startPage(pageInfo);
            author.draw(page.getCanvas());
            document.finishPage(page);
            String pdfName = "pdfdemo";
            File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS));
            try {outputFile.createNewFile();
                OutputStream out = new FileOutputStream(outputFile);
                document.writeTo(out);
                document.close();
                out.close();

        }
            catch (IOException e) {
                e.printStackTrace();
            }
            return outputFile.getPath();
    }

当我在Android Studio中运行程序时,我会收到几个错误信息,第一个是:Error:(44, 45) error: PageInfo() is not public in PageInfo; cannot be accessed from outside package。我已将PdfGEneration任务更改为public,但这似乎无法解决问题。我应该做什么,为什么?

第二个错误是这一个:Error:(49, 31) error: no suitable constructor found for File(File) constructor File.File(String) is not applicable (argument mismatch; File cannot be converted to String) constructor File.File(URI) is not applicable (argument mismatch; File cannot be converted to URI) 这里有什么问题?我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

看起来PageInfo构造函数是私有的。而不是

  

new PdfDocument.PageInfo()。Builder(20,20,pageNumber).create();

尝试

  

new PdfDocument.PageInfo.Builder(20,20,pageNumber).create();