PdfBox-Android
PdfBox-Android copied to clipboard
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.InputStream.close()' on a null object reference
Describe the bug I am trying to print string as pdf file In the Custom created PrintDocumnetAdapter. I am getting crash, when I create release build only. IT was working fine with the old Gradle version but after update Gradle version I am facing this issue.
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.InputStream.close()' on a null object reference
at com.tom_roush.fontbox.ttf.MemoryTTFDataStream.<init>(MemoryTTFDataStream.java:56)
at com.tom_roush.fontbox.ttf.TTFParser.parse(TTFParser.java:108)
at com.tom_roush.pdfbox.pdmodel.font.PDType0Font.load(PDType0Font.java:98)
at com.jio.editor.MyPdfAdapter.getFont(MyPdfAdapter.java:189)
To reproduce
private PDFont getFont() {
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
document.addPage(page);
PDType0Font font = null;
try {
font = PDType0Font.load(document, PDDocument.class.getResourceAsStream("font/times.ttf"), true);
} catch (IOException e) {
e.printStackTrace();
}
return font;
}
Expected behavior I dont know why its getting crash only when I use latest android gradle version but not crashing in old version " classpath 'com.android.tools.build:gradle:4.1.1'"
Environment details:
- PdfBox-Android version: com.tom-roush:pdfbox-android:2.0.27.0'
- Android API version: 33
- jvmTarget = '1.8'
- kotlin version = 1.8.0 -gradle-wraper.property: = gradle-8.0-bin.zip
Here is the Windows system configuration:- Java version: 18.0.2 Android studio version :Flamingo | 2022.2.1 Patch 2
Please check whether PDDocument.class.getResourceAsStream("font/times.ttf")
is null.