1

I'm using RxRoom with Kotlin. In my Dao class If I use this:

@Insert fun insertPaymentRef(paymentRef: PaymentRef): Single<Long>

Or this:

@Insert
fun insertPaymentRef(paymentRef: PaymentRef): Completable

the generated Dao class throws this error

error: local variable paymentRef is accessed from within inner class; needs to be declared final

A sneek peak in the generated class is this:

public Single<Long> insertPaymentRef(PaymentRef paymentRef) {
return Single.fromCallable(new Callable<Long>() {
  @Override
  public Long call() throws Exception {
    __db.beginTransaction();
    try {
      long _result = __insertionAdapterOfPaymentRef.insertAndReturnId(paymentRef);
      __db.setTransactionSuccessful();
      return _result;
    } finally {
      __db.endTransaction();
    }
  }
});

}

The only time I don't get this error is if I only make my insert call like this:

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertPaymentRef(paymentRef: PaymentRef)

How do I make the INSERT call work in RxRoom: I've included RxRoom dependency and it works because if I try doing GET calls like this

@Query(PaymentRefDbConstants.QUERY_PAYMENT_REF)
fun getPaymentRef(): Single<PaymentRef>

It works

  • Just came across [this post](https://stackoverflow.com/a/40563463/5015207) on final function parameters for Kotlin - if this is true then you've just encountered yet another Kotlin bug – Bö macht Blau Nov 29 '18 at 20:18
  • 1
    The error says that there is a problem with variable `users` if I understand properly. Where is that variable? Can't see it in the code you posted. – dglozano Nov 29 '18 at 20:24
  • It's actually paymentRef, it happened in the UsersDao also. I'm making that edit now. Thanks – Ememobong AkpanEkpo Nov 30 '18 at 00:04

0 Answers0