我试着去使用此代码的部分:更准确地说这部分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)
这里有什么问题?我能做些什么来解决这个问题?
问题是使用'PdfDocument.PageInfo'。看起来这个班不公开。检查此类所属的代码。 –
至于第二个错误,看看你传递给File构造函数的对象的类型 - 这是不允许的,因为错误信息告诉你。 –
但它说:“PageInfo()在”android.graphics.pdf.Pdfdocument.pageinfo“中没有公开,所以不应该自动导入一个类?@HovercraftFullOfEels – Rasmus