Using Java constants from Scala in Android

I have a strange development problem in Scala on Android. I am using the sbt android plugin and now I am trying to get the content providers to work, but ...

I need to get an array of columns, and I do it exactly the same as in the tutorial: http://developer.android.com/guide/topics/providers/content-providers.html

Just replaced the Java array code with Scala one. It looks like this:

val projection = Array( People.NAME, People.NUMBER ) 

But then the Scala compiler returns an error

 [error] /home/exine/proj/hello-world/src/main/scala/Activity.scala:12: value NAME is not a member of object android.provider.Contacts.People [error] People.NAME, [error] ^ [error] one error found 

And in fact, this is a member of this object, and it is defined in the android.provider.Contacts.PeopleColumns interface (which is implemented by people). I tried to get it directly from PeopleColumns without any success (same error). Is getting constants from Java in Scala somewhat different, or did I just make a stupid mistake somewhere?

UPDATE:

The next problem. When using ContactsContract.Contacts, the error remains the same, and when I try another method, I can not access ContactsContract.ContactsColumns directly, because it is a secure interface.

 [error] /home/exine/proj/hello-world/src/main/scala/Activity.scala:13: object ContactsColumns cannot be accessed in object android.provider.ContactsContract [error] ContactsColumns.LOOKUP_KEY, [error] ^ [error] one error found 
+7
source share
2 answers

This context has been deprecated by reference. The new ContactsContract method, and you should use it.

In any case, the problem is that this constant is static , defined on the interface PeopleColumns . Static inheritance is what Java has, but Scala doesn't, and it frowned even on Java.

Try importing PeopleColumns and use PeopleColumns.NAME - or, better yet, use a new, not outdated way of doing things. Which I do not explain, because I do not know the development of Android.

+2
source

I think you will have to import the static variables from android.provider.Contacts.PeopleColumns._ before you can access them.

0
source