I have imported my db in several structures using cblite-tool…
import ../db/flickr/
one way of building the db was using the couchbase example on their android-java tutorial
[{"photo":{"id":"51334404495","owner":"131209910@N02","secret":"a0b873fda8","server":"65535","farm":66,"title":"Evening mood...","ispublic":1,"isfriend":0,"isfamily":0,"url_s":"https:\/\/live.staticflickr.com\/65535\/51334404495_a0b873fda8_m.jpg","height_s":125,"width_s":240}},
{"photo":{"id":"51333393876","owner":"134230993@N02","secret":"570648e7a0","server":"65535","farm":66,"title":"Blue denim...","ispublic":1,"isfriend":0,"isfamily":0,"url_s":"https:\/\/live.staticflickr.com\/65535\/51333393876_570648e7a0_m.jpg","height_s":180,"width_s":240}},
{"photo":{"id":"51331253286","owner":"39652177@N04","secret":"07494972e6","server":"65535","farm":66,"title":"Great blue heron","ispublic":1,"isfriend":0,"isfamily":0,"url_s":"https:\/\/live.staticflickr.com\/65535\/51331253286_07494972e6_m.jpg","height_s":189,"width_s":240}},...
after that i run the command reindex
on cblite tool.
i used these 2 ways to get them to the app, but bother weren’t useful
i created a model for the data in db
data class photo(
val owner: String,
val server: String,
val height_s: String,
val width_s: String,
val url_s: String,
val ispublic: String,
val isfriend: String,
val farm: String,
var id: String,
val secret: String,
val title: String,
val isfamily: String
)
Query:
val listQuery: Query = QueryBuilder.select(SelectResult.all())
.from(DataSource.database(database))
and tried a for loop
to get the data using their keys into the front end (i’m working on JetPack compose)
for (result in listQuery.execute().allResults()){
println(result.getDictionary(0).getString("owner"))
}
but that didn’t work, i tried to print the result in console for once type but the app crash every time.
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.couchbase.lite.Dictionary.getString(java.lang.String)' on a null object reference
only when i get it as an array that i get the whole data on the same index
for (result in listQuery.execute().allResults()){
println(result.getArray(0).toList())
}
it shows like this:
I/System.out: [{photo={owner=131209910@N02, server=65535, height_s=125, width_s=240, url_s=https://live.staticflickr.com/65535/51334404495_a0b873fda8_m.jpg, ispublic=1, isfriend=0, farm=66, id=51334404495, secret=a0b873fda8, title=Evening mood..., isfamily=0}}, {photo={owner=134230993@N02, server=65535, height_s=180, width_s=240, url_s=https://live.staticflickr.com/65535/51333393876_570648e7a0_m.jpg, ispublic=1, isfriend=0, farm=66, id=51333393876, secret=570648e7a0, title=Blue denim..., isfamily=0}}, {photo={owner=39652177@N04, server=65535, height_s=189, width_s=240, url_s=https://live.staticflickr.com/65535/51331253286_07494972e6_m.jpg, ispublic=1, isfriend=0, farm=66, id=51331253286, secret=07494972e6, title=Great blue heron, isfamily=0}}...
but i can’t convert this array into List<photo>
it always remains MutableList<Any?>
even if i cast it. or try to create a loop to add it into a list the app crash.
the second way was using a document to get the data and it is the same issue with the list type and items within the array.
what is missing or wrong???