Skip to content

call DSM_Lock get NullPointerException #10

@here-mei

Description

@here-mei

When I call this program, the following methods work without any issues: Twain.setSourceManager(); TwainScanner.getScanner(); TwainSourceManager.selectSource(); TwainSourceManager.openSource(). I can also obtain the state 4 through twainSource.getState(). However, when I call twainSource.enable(); and twainSource.getCapabilities(), a NullPointerException is thrown. After tracing the code, I found that Twain.DSM_Lock returns null, while the passed parameter Pointer is not null. Below is the complete error stack and calling code. Could you please help me analyze where the problem lies and how to solve it?
console printline :
Initializing TWAIN environment...

  • Selected source: X2110A
    TWAIN GET: 0f10ffff000000000000000000000000,0f1004007800b4e68701000000000000,null
  • Source opened
  • Source state: 4
    TWAIN GET: 0f10ffff000000000000000000000000,0f1004008800b4e68701000000000000,null
  • Source is online: true
    TWAIN GET: 0301ffff000000000000000000000000,030104009800b4e68701000000000000,null
    General error occurred:
    java.lang.NullPointerException
    at free.lucifer.jtwain.utils.TwainUtils.getINT16(TwainUtils.java:25)
    at free.lucifer.jtwain.variable.TwainContainer.(TwainContainer.java:41)
    at free.lucifer.jtwain.variable.TwainEnumeration.(TwainEnumeration.java:36)
    at free.lucifer.jtwain.TwainCapability.get(TwainCapability.java:94)
    at free.lucifer.jtwain.TwainCapability.get(TwainCapability.java:105)
    at free.lucifer.jtwain.TwainCapability.get(TwainCapability.java:109)
    at free.lucifer.jtwain.TwainCapability.(TwainCapability.java:45)
    at free.lucifer.jtwain.TwainCapability$XferMech.(TwainCapability.java:288)
    at free.lucifer.jtwain.TwainSource.enable(TwainSource.java:339)
    at free.lucifer.jtwain.App.main(App.java:30)

calling code:
public class App {

public static void main(String[] args) {
    try {

        System.out.println("Initializing TWAIN environment...");

// Twain.init();

        TwainSourceManager twainSourceManager = Twain.getSourceManager();
        TwainScanner twainScanner = TwainScanner.getScanner();
        TwainSource twainSource = twainSourceManager.selectSource();
        System.out.println("- Selected source: " + twainSource.getProductName());

        twainSource = twainSourceManager.openSource();
        System.out.println("- Source opened");
        System.out.println("- Source state: " + twainSource.getState());
        System.out.println("- Source is online: " + twainSource.isDeviceOnline());
        twainSource.enable();

        TwainCapability[] twainCapabilities = twainSource.getCapabilities();
        for (TwainCapability capability : twainCapabilities) {
            System.out.println("- Capability: " + capability.cap);
            if (capability.querySupport() == 1) {
                System.out.println("- Support: " + capability.querySupport());
            }
        }


        System.out.println("\nScan completed. Closing resources...");

        Twain.done();
        System.out.println("All resources released.");

    } catch (TwainException e) {
        System.err.println("TWAIN error occurred:");
        e.printStackTrace();
    } catch (Exception e) {
        System.err.println("General error occurred:");
        e.printStackTrace();
    }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions