2
votes

In my Scala Android project I'm getting the curious error:

type mismatch; found : android.accounts.android.accounts.AccountManagerCallback[Boolean] required: android.accounts.android.accounts.AccountManagerCallback[Boolean]

when calling 'removeAccount' in the code below:

val accountManager = android.accounts.AccountManager.get(this)
for (account <- accountManager.getAccounts) {
    accountManager.removeAccount(account,
      new AccountManagerCallback[Boolean] {
        override def run(result: AccountManagerFuture[Boolean]) {
          try {
            result.getResult(3, TimeUnit.SECONDS)
          } catch {
            case e: Exception => Log.d(getClass.getName, "exception: ", e)
          }
        }
     }, new Handler())
  }
}

Any ideas on what's going wrong and what can I do to placate the type checker?

1

1 Answers

1
votes

.. just worked it out, there was a mix up between java.lang.Boolean and scala.Boolean. Need to be explicit in the class type parameters...

val accountManager = android.accounts.AccountManager.get(this)
for (account <- accountManager.getAccounts) {
accountManager.removeAccount(account,
  new AccountManagerCallback[java.lang.Boolean] {
    override def run(result: AccountManagerFuture[java.lang.Boolean]) {
      try {
        result.getResult(3, TimeUnit.SECONDS)
      } catch {
        case e: Exception => Log.d(getClass.getName, "exception: ", e)
      }
    }
 }, new Handler())