I am trying to use the gorgeous Kotlin and SugarORM in combination for Android development and have my models set up like this:
import com.orm.SugarRecord
public class Contact : SugarRecord<Contact>() {
var name : String = ""
var phoneNumber : String = ""
var info : String? = null
}
Of course I have also changed the AndroidManifest.xml
:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:replace="android:icon"
android:name="com.orm.SugarApp">
<meta-data android:name="DATABASE" android:value="database.db" />
<meta-data android:name="VERSION" android:value="1" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="/* same as package attribute on manifest element */" />
<activity>…</activity>
</application>
Now I'm trying to use the model inside MainActivity.kt
:
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val contacts = Contact.listAll(javaClass(Contact))
// or val contacts : List<Contact> = Contact.listAll(javaClass(Contact))
return true
}
But getting the error Unresolved reference: listAll
, meaning the static method call failed for some reason. Same with methods like find
… did I overlook something?
Thanks in advance for any help.
As those are static methods, you need to call them on the declaring class
SugarRecord
. Your code should be: