pilgr / Paper

Paper is a fast NoSQL-like storage for Java/Kotlin objects on Android with automatic schema migration support.
Apache License 2.0
2.35k stars 234 forks source link

Paper with kotlin: write and read function is not working #156

Closed weihaolem closed 5 years ago

weihaolem commented 5 years ago

Hi, sorry for asking a question. I would like to ask how to make it works? I have added dependency and initialize Paper, but the function still not working ("write" function do not replace the value of the parameter; "read" function caused the application fail/not working).

This is my class where the value will store: class Prevalent { companion object{ val UserPhoneKey : String = "UserPhone" val UserPasswordKey : String = "UserPassword" }}

Those is the lines I used Paper library: ->write function Paper.book().write(Prevalent.UserPhoneKey, phoneNo) Toast.makeText(this@LoginActivity, "test ${Prevalent.UserPhoneKey} test", Toast.LENGTH_LONG).show() *Toast show default value instead of showing phone number

->read function val userPhone:String = Paper.book().read(Prevalent.UserPhoneKey) *tried a lot of times, read function cause application fail

Sorry for my bad English.

Thank you for your help.

pilgr commented 5 years ago

Do not use Paper.book().write and read functions in UI thread, that may cause the issue.

If you can provide more detailed error message or stacktrace I probably can give more detailed answer.

weihaolem commented 5 years ago

It is worked after I restart android studio. Maybe the implementation did not start after I add its dependency.

Thank you for your help!