question

wsadiq avatar image
wsadiq asked Dan commented

Null pointer while getting item quantity

We have a native app on Clover. At one point in the app, we are trying to get quantity of line item and getting a null pointer exception.

  1. List<LineItem> items = order.getLineItems();
  2. for (LineItem item : items) {
  3. long qty = item.hasUnitQty() ? item.getUnitQty() : 1000;
  4. }
In the above code, Order has been obtained using OrderConnector. The line that gets the item's quantity is generating a null pointer exception. Can anybody help explain what is wrong here?

Thanks in advance.
OrdersLineItems
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.

1 Answer

·
Dan avatar image
Dan answered Dan commented
It looks like LineItem#isNotNullUnitQty() is what you want.

/** Checks whether the 'unitQty' field has been set, however the value could be null */
public boolean hasUnitQty() {
return genClient.cacheHasKey(CacheKey.unitQty);
}

/** Checks whether the 'unitQty' field is set and is not null */
public boolean isNotNullUnitQty() {
return genClient.cacheValueIsNotNull(CacheKey.unitQty);
}
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.

Write an Answer

HTML Editor


Add some details...
Characters : 0
Tab to the formatting toolbar with Alt/Option + F10. If inside toolbar, press ESC to return to editor. Hint: Notify or tag a user in this post by typing @username.

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