Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.InputStream.close()' on a null object reference #520

Open
devsundar opened this issue Jul 19, 2023 · 1 comment
Labels
type: bug Existing feature doesn't work correctly

Comments

@devsundar
Copy link

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

@devsundar devsundar added the type: bug Existing feature doesn't work correctly label Jul 19, 2023
@THausherr
Copy link

Please check whether PDDocument.class.getResourceAsStream("font/times.ttf") is null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Existing feature doesn't work correctly
Projects
None yet
Development

No branches or pull requests

2 participants