Java 公共类不是公共类?
我正在尝试使用部分代码: 更确切地说,这一部分:Java 公共类不是公共类?,java,android,Java,Android,我正在尝试使用部分代码: 更确切地说,这一部分: public class PdfGenerationTask extends AsyncTask<Void, Void,String>{ protected String doInBackground(Void... params) { PdfDocument document = new PdfDocument(); View author = findView
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中运行该程序时,我收到了几个错误消息,第一个是:错误:44,45错误:PageInfo在PageInfo中不公开;无法从包外部访问。我已经将PdfGEneration任务更改为public,但这似乎无法解决问题。我该怎么做,为什么
第二个错误是:错误:49,31错误:找不到适合FileFile的构造函数
构造函数文件.FileString不适用
参数不匹配;无法将文件转换为字符串
构造函数文件.FileURI不适用
参数不匹配;无法将文件转换为URI
这里有什么问题?如何解决该问题?看起来PageInfo构造函数是私有的。而不是 新建PdfDocument.PageInfo.Builder20,20,pageNumber.create 试一试 新建PdfDocument.PageInfo.Builder20,20,pageNumber.create
该问题正在使用PdfDocument.PageInfo。看起来那个类不是公开的。检查该类所属的代码。至于第二个错误,请查看传递到文件构造函数中的对象类型-这是不允许的,错误消息告诉您。但是它说:PageInfo在android.graphics.pdf.Pdfdocument.PageInfo中不是公共的,所以不是应该自动导入的类吗@是的,这个看起来更好。1+Woho!谢谢@34m0