question

Nimila Hiranya avatar image
Nimila Hiranya asked Nimila Hiranya edited

Clover App Crash on Label Printing

I'm trying to implement Add a sticky label order printer on my App. I already have ORDER and RECEIPT printer integrations. For LABEL, I upgraded my Clover SDK to 262.2.

I'm attempting to print a test from the following code.

new AsyncTask<Void, Void, Printer>() {
                @Override
                protected Printer doInBackground(Void... params) {
                    return getPrinter(Category.LABEL);
                }
                @Override
                protected void onPostExecute(Printer printer) {
                    if (printer == null) {
                        return;
                    }
                    if (mOrder != null) {
                        List<String> itemIdList = Stream.of(mOrder.getLineItems()).map(lineItem -> lineItem.getId()).collect(Collectors.toList());
                        ArrayList<String> itemIds = new ArrayList<>(itemIdList);
                        Log.d(TAG, "Printing Order Label");
                        StaticLabelPrintJob print_job = new StaticLabelPrintJob
                                .Builder()
                                .itemIds(itemIds)
                                .markPrinted(true)
                                .reprintAllowed(true)
                                .build();
                        print_job.print(thisActivity, account, printer);
                    } else {
                        Log.d(TAG, "Order is null");
                    }
                }
            }.execute();

mOrder is of type Order from clover SDK. I'm trying to use StaticLabelPrintJob to invoke a print. I have already added my Label Printer as well (Epson TM-L90 PLUS).

device-2021-07-07-151347.png

When that code is executed, the Clover app crashes with the message "Clover has stopped". And in the print jobs queue, you can see the print job as an error.

On the logcat, I'm seeing the following:

2021-07-07 15:26:00.927 11928-12381/? E/AndroidRuntime: FATAL EXCEPTION: IntentService[com.clover.engine.printer.PrintService]
    Process: com.clover.engine, PID: 11928
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.clover.sdk.v3.order.Order.isNotNullLineItems()' on a null object reference
        at com.clover.common2.orders.v3.OrderUtils.setLineItemsPrinted(OrderUtils.java:925)
        at com.clover.engine.printer.PrintService.doEnqueue(PrintService.java:177)
        at com.clover.engine.printer.PrintService.onHandleIntent(PrintService.java:139)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.os.HandlerThread.run(HandlerThread.java:65)

And after this, even a Print Test Receipt doesn't work.

My DeviKit is a Clover Mini 2.

com.clover.engine versionCode: 2131 versionName: 2.0-2131

com.clover.printers versionCode: 1189 versionName: 1.0-1189

com.clover.epsonprinter versionCode: 16 versionName: 1.0-16

What is causing this? What am I doing wrong? I'll add the Order ID I tested with in the comments for the moderators. Thanks.

Print
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nimila Hiranya avatar image
Nimila Hiranya answered Nimila Hiranya edited

The following worked. Rather than using the methods from StaticLabelPrintJob, I used the builder from the parent StaticOrderBasedPrintJob, and set the Order directly. Which worked.

new AsyncTask<Void, Void, Printer>() {
                @Override
                protected Printer doInBackground(Void... params) {
                    return getPrinter(Category.LABEL);
                }
                @Override
                protected void onPostExecute(Printer printer) {
                    if (printer == null) {
                        return;
                    }
                    if (mOrder != null) {
                        Log.d(TAG, "Printing Order Label");
                        PrintJob printJob = new StaticLabelPrintJob.Builder()
                                .order(mOrder)
                                .build();
                        printJob.print(thisActivity, account, printer);
                    } else {
                        Log.d(TAG, "Order is null");
                    }
                }
            }.execute();


10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

saru-fivestars avatar image
saru-fivestars answered David Marginian Deactivated converted comment to answer

Clover team.. Please advise.. this is holding up a 25 site install.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Marginian avatar image
David Marginian Deactivated answered

I am not very familiar with this API, but from looking at the exception (and our code) the order is null. I would try setting the order and I am guessing that will resolve the issue.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community