2017-02-15 7 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(); 
    } 

私は、私はいくつかのエラーmessegesを得るのAndroid Studioでプログラムを実行すると、最初のものは次のとおりです。Error:(44, 45) error: PageInfo() is not public in PageInfo; cannot be accessed from outside package。私はPdfGEnerationタスクをpublicに変更しましたが、それは問題を解決していないようです。代わりに私は何をすべきなのですか?なぜですか?

2番目のエラーは次のとおりです。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

2番目のエラーについては、Fileコンストラクタに渡すオブジェクトのタイプを見てください。エラーメッセージがあなたに伝えているので、許可されていません。 –

+0

でも、「PageInfo()はandroid.graphics.pdf.Pdfdocument.pageinfo」には公開されていませんので、自動的にインポートするクラスはありませんか?@HovercraftFullOfEels – Rasmus

答えて

1

PageInfoコンストラクタがprivateであるように見えます。代わりに

新しいPdfDocument.PageInfo()。Builder(20,20、pageNumber).create();

新しいPdfDocument.PageInfo.Builder(20,20、ページ番号).createを()してみてください。

+0

はい、これは見た目が良くなりました(1+) –

+0

Woho !ありがとうございます@ 34m0 – Rasmus

+0

ああ、歓迎です:) – 34m0

関連する問題