-1
I’m in two trouble.
The Toast
in my method returns me the following error:
The method makeText(Context, Charsequence, int) in the type Toast is not applicable for the Arguments (Gerarrelatorio, String, int)
How to display a default error message? Like for example "Document not created".
To create the folder I am using this code, I tested in the emulator and nothing happened, creating the PDF file in the folder Documents with this line of right:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);
But only in the API 19, so I wanted to create the folder and check if it exists or not, so I could use in Android 4.0 onward.
public void CriarRelatorio(ClienteClass objCliente, EquipamentoClass objEquipamento, ServicoClass objServico, PecasClass objPecas){
try {
Document document = new Document();
File direct = new File(Environment.getExternalStorageDirectory()+"/Relatorios");
if(!direct.exists()) {
if(direct.mkdir()); //se não existir o diretorio e criado
}
File pdffile = new File(direct, "RelatorioTeste.pdf");
PdfWriter.getInstance(document, new FileOutputStream(pdffile));
document.open();
addMetaData(document);
addTituloRelatorio(document);
addConteudo(document);
document.close();
Toast.makeText(this, "Arquivo criado com sucesso", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
// TODO: handle exception
}
}
Could you check if an exception is thrown on that catch block? If so, post the stacktrace.
– Wakim
Your class
GerarRelatorio
is aActivity
orFragment
?– Lucas Santos
Actually I had created only a published class with a method Generate Report, but in my example here I did, the method is within an Activity even, I thought I could call the method of creating the PDF by the main Activity.
– Vinicius