question

Alan avatar image
Alan asked Alan commented

StaticOrderPrintJob null exception on isReprint

Hi Clover Dev,

I'm having a hard time trying to get the StaticOrderPrintJob to print an orders line items

#1:

StaticOrderPrintJob.Builder().order(order).build().print(Activity.this, account);

#2

I'm atleast able to get it to print dates, times, and the order number when I include a string array in .itemIds(stringArray) e.g:

StaticOrderPrintJob.Builder().markPrinted(true).reprintAllowed(true).itemIds(itemIds).order(order).build().print(Activity.this, account);

But none of the line items print in that case.. I'm just getting the dates and order id.

Below is the log output when it crashes with attempt #1. I'd love to take a look at that com.clover.engine.printer.PrintService class to see what i'm missing. Is there any documentation on what's required? Is it something missing from my order object by any chance? Thanks

08-31 22:41:44.065 2464-2464/com.example.pshee.espressio W/ContextImpl: Implicit intents with startService are not safe: Intent { act=com.clover.sdk.printer.intent.action.PRINT_SERVICE (has extras) } android.content.ContextWrapper.startService:494 com.clover.sdk.v1.printer.job.PrintJob.print:99 com.clover.sdk.v1.printer.job.PrintJob.print:91 
08-31 22:41:44.506 27243-3795/? E/AndroidRuntime: FATAL EXCEPTION:    IntentService[com.clover.engine.printer.PrintService]
Process: com.clover.engine, PID: 27243
java.lang.NullPointerException
at com.clover.engine.printer.PrintService.isReprint(PrintService.java:197)
at com.clover.engine.printer.PrintService.onHandleIntent(PrintService.java:81)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
OrdersPrint
10 |2000

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

Alan avatar image
Alan answered Alan commented

To answer my own question:

I set in my order object with:

lineItem.setPrinted(false);
2 comments
10 |2000

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

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

How did you create the order and line items?

0 Likes 0 ·
Alan avatar image Alan commented ·

I'm building them from my own data. I got to a point where I could print the full order only if none of the items had modifications. I'm obviously not creating the modifications properly as its hitting a similar NullException in a class I have no access to. I've given up on StaticOrderPrintJob. I have the ViewJobPrint working now, I just need to make it bigger and pretty! Thanks for looking Jeff

0 Likes 0 ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered Alan commented

We expect that people use the methods in OrderConnector to create and build the order. Unfortunately there are a few assumptions the receipt code makes w/ regard to the structure of the order as it would be built from that. That being said, it's a bug that it crashes in that case. It is just poor coding on our part that we didn't perform a null check on the printed flag.

If you want to use StaticOrderPrintJob with your own hand-built Order object, I'd suggest you look at the JSON for an order created by the Clover Register app and try to mimic all of the fields therein. ViewPrintJob is fine too of course.

1 comment
10 |2000

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

Alan avatar image Alan commented ·

I appreciate it Jeff, I've since found ViewPrintJob to work quite well for what I need. Thanks for the help!

0 Likes 0 ·

Welcome to the
Clover Developer Community