Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private AddCartItemDialog.CartItemListener cartItemListener = new AddCartItemDialog.CartItemListener() {
- @Override
- public void onOkClick(Product cartItem, int quantity) {
- realm.executeTransactionAsync(new Realm.Transaction() {
- @Override
- public void execute(Realm bgRealm) {
- DraftInvoice draftInvoice = bgRealm.where(DraftInvoice.class).equalTo("shop.id", shopId).findFirst();
- InvoiceItem invoiceItem = bgRealm.createObject(InvoiceItem.class);
- invoiceItem.setPrice(cartItem.getPrice());
- invoiceItem.setId(cartItem.getId());
- invoiceItem.setQuantity(quantity);
- invoiceItem.calculateTotal();
- draftInvoice.getInvoiceItems().add(invoiceItem);
- updateCartItemCount(draftInvoice.getInvoiceItems().size());
- }
- }, () -> {
- }, error -> {
- error.printStackTrace();
- Logger.e(error.getMessage());
- });
- }
- @Override
- public void onCancelClick() {
- }
- };
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: java.lang.IllegalStateException: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at io.realm.BaseRealm.checkIfValid(BaseRealm.java:449)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at io.realm.ProductRealmProxy.realmGet$price(ProductRealmProxy.java:159)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at com.example.realshoptest.models.Product.getPrice(Product.java:75)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at com.example.realshoptest.NewInvoiceActivity$1$1.execute(NewInvoiceActivity.java:76)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at io.realm.Realm$1.run(Realm.java:1187)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at io.realm.internal.async.BgPriorityRunnable.run(BgPriorityRunnable.java:34)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest W/System.err: at java.lang.Thread.run(Thread.java:818)
- 08-28 15:10:25.214 4996-4996/com.example.realshoptest E/TestShopApp: Realm access from incorrect thread. Realm objects can only be accessed on the thread they were created.
- public void onOkClick(Product cartItem, int quantity) {
- realm.executeTransactionAsync(new Realm.Transaction() {
- @Override
- public void execute(Realm bgRealm) {
- invoiceItem.setPrice(cartItem.getPrice());
- public void onOkClick(Product cartItem, int quantity) {
- final long cartItemId = cartItem.getId();
- final String price = cartItem.getPrice();
- realm.executeTransactionAsync(new Realm.Transaction() {
- @Override
- public void execute(Realm bgRealm) {
- DraftInvoice draftInvoice = bgRealm.where(DraftInvoice.class).equalTo("shop.id", shopId).findFirst();
- InvoiceItem invoiceItem = bgRealm.createObject(InvoiceItem.class);
- invoiceItem.setPrice(price);
- invoiceItem.setId(cartItemId);
- public void onOkClick(Product cartItem, int quantity) {
- final long cartItemId = cartItem.getId();
- realm.executeTransactionAsync(new Realm.Transaction() {
- @Override
- public void execute(Realm bgRealm) {
- Product product = bgRealm.where(Product.class).equalTo("id", cartItemId).findFirst();
- DraftInvoice draftInvoice = bgRealm.where(DraftInvoice.class).equalTo("shop.id", shopId).findFirst();
- InvoiceItem invoiceItem = bgRealm.createObject(InvoiceItem.class);
- invoiceItem.setPrice(product.getPrice());
- invoiceItem.setId(cartItemId);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement