使用Star Printer SDK时发生NullPointerException

时间:2019-02-15 13:13:06

标签: java printing nullpointerexception

在Star TSP100III打印机上执行打印作业后,我收到以下错误消息。

#0. Crashed: Thread-58
       at com.starmicronics.stario.e.readPort(Unknown Source)
       at com.starmicronics.stario.e.retreiveStatus(Unknown Source)
       at com.starmicronics.starioextension.StarIoExtManager$g.run(SourceFile:875)

--

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.hardware.usb.UsbDeviceConnection.bulkTransfer(android.hardware.usb.UsbEndpoint, byte[], int, int)' on a null object reference
       at com.starmicronics.stario.e.readPort(Unknown Source)
       at com.starmicronics.stario.e.retreiveStatus(Unknown Source)
       at com.starmicronics.starioextension.StarIoExtManager$g.run(SourceFile:875)

#0. Crashed: Thread-58
       at com.starmicronics.stario.e.readPort(Unknown Source)
       at com.starmicronics.stario.e.retreiveStatus(Unknown Source)
       at com.starmicronics.starioextension.StarIoExtManager$g.run(SourceFile:875)

#1. FinalizerWatchdogDaemon
       at java.lang.Object.wait(Object.java)
       at java.lang.Daemons$FinalizerWatchdogDaemon.sleepUntilNeeded(Daemons.java:269)
       at java.lang.Daemons$FinalizerWatchdogDaemon.run(Daemons.java:249)
       at java.lang.Thread.run(Thread.java:761)

#2. ReferenceQueueDaemon
       at java.lang.Object.wait(Object.java)
       at java.lang.Daemons$ReferenceQueueDaemon.run(Daemons.java:150)
       at java.lang.Thread.run(Thread.java:761)

#3. pool-42-thread-1
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor$(Thread.java:2127)
       at sun.misc.Unsafe.park(Unsafe.java:325)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1091)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1084)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

#4. pool-47-thread-1
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor$(Thread.java:2127)
       at sun.misc.Unsafe.park(Unsafe.java:325)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1091)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1084)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

#5. pool-9-thread-1
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor$(Thread.java:2127)
       at sun.misc.Unsafe.park(Unsafe.java:325)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1091)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1084)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

#6. pool-11-thread-1
       at java.lang.Object.wait(Object.java)
       at java.lang.Thread.parkFor$(Thread.java:2127)
       at sun.misc.Unsafe.park(Unsafe.java:325)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1091)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1084)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

但是异常堆栈跟踪没有指向我的代码导致崩溃的任何地方。

protected Void doInBackground(String... params) {
        StarIOPort port = null;
        try {
            // Port open
            port = starIoExtManager.getPort();
            // Print end monitoring -Start
            status = port.beginCheckedBlock();
            //printer is online
            byte[] command = PrinterFunctions.createRasterData(selectedStarReceiptPrinter.getEmulation(), bitmapToPrint, selectedStarReceiptPrinter.getPaperWidth(), true);
            port.writePort(command, 0, command.length);
            bitmapToPrint.recycle();
            // Print end monitoring -Endt
            status = port.endCheckedBlock();

        } catch (StarIOPortException e) {
            // Error
            starPrinterException = e;
            Log.i(TAG, ">>>>>>>>>>>>>>>>> PRINTER ERROR: 2 - BitmapPrintAsyncTask | StarIOPortException");
        } catch (Exception e) {
            e.printStackTrace();
            Log.i(TAG, ">>>>>>>>>>>>>>>>> PRINTER ERROR: 2 - BitmapPrintAsyncTask | Exception");
        }finally {
            try {
                // Port close
                StarIOPort.releasePort(port);

            } catch (StarIOPortException e) {
            }
        }
        return null;
    }

这是使用打印功能的示例代码。我正在使用StarIoExtManager处理打印机状态。

如何在这样的实例中找到根本原因?

0 个答案:

没有答案