0

I am trying to pre-populate a room database with some data using DB Browser for sqlite.

I have a table defined with (name: String, score:Int, image:Int). That image field stores an image from drawable folder so the example for an insert would be :

INSERT INTO player (name,score,image) VALUES ("Mike", 31, R.drawable.mike)

Since the table field is Int, DB Browser wont let me store R.drawable.mike which is the image location in android studio as it expects a number. Error :

Execution finished with errors.
Result: no such column: R.drawable.mike
At line 1:
INSERT INTO player (name,score,image) VALUES ("Mike", 31, R.drawable.mike)

I have tried using a BLOB type for image but it returns the same error as above.

Any ideas on how I can do this ? If I define image to be a string how can I make android studio read "R.drawable.mike" as id location later in the code?

Or how can I prepopulate a room database with such data in some other way ?

4
  • I am considering using a string anyway and then converting it later like this (but in kotlin) : String name = "your_drawable"; int id = getResources().getIdentifier(name, "drawable", getPackageName()); Drawable drawable = getResources().getDrawable(id); Commented Jul 11, 2022 at 2:03
  • Clearly this piece of data is a string: R.drawable.mike. I'm not familiar with android studio etc. Does it at some point map to an int? That must occur in your application code somewhere. Commented Jul 11, 2022 at 2:17
  • I believe that at runtime it maps to the location of the image in the resources folder. Android studio considers that to be an int as it points to a location in the phone's memory. But the DB browser does not have such structure/system. Commented Jul 11, 2022 at 3:12
  • Perhaps you should post the bit of code that is meant to utilise this piece of data. Commented Jul 11, 2022 at 3:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.