2017-02-15 64 views
0

我試着去使用此代碼的部分:更準確地說這部分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任務更改爲公開,但似乎無法解決問題。我應該怎麼做,爲什麼?

第二個錯誤是這一個: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) 這裏有什麼問題?我能做些什麼來解決這個問題?

+0

問題是使用'PdfDocument.PageInfo'。看起來這個班不公開。檢查此類所屬的代碼。 –

+0

至於第二個錯誤,看看你傳遞給File構造函數的對象的類型 - 這是不允許的,因爲錯誤信息告訴你。 –

+0

但它說:「PageInfo()在」android.graphics.pdf.Pdfdocument.pageinfo「中沒有公開,所以不應該自動導入一個類?@HovercraftFullOfEels – Rasmus

回答

1

看起來像PageInfo構造函數是私有的。而不是

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

嘗試

新PdfDocument.PageInfo.Builder(20,20,PAGENUMBER).create();

+0

是的,這看起來更好。(1+) –

+0

Woho !謝謝@ 34m0 – Rasmus

+0

哦,歡迎:) – 34m0