1

I'm trying to store a create database script (a rather lengthy one) in the strings.xml file (noobie here, haven't figured out a better place to put it yet) it does show up in the generated R class:

public static final class string {
        public static final int app_name=0x7f040001;
        public static final int create_database=0x7f040002; //this one here
        public static final int hello=0x7f040000;
    }

but when I try this in the code:

DATABASE_CREATE = R.string.create_database;

'create_database' is not available. Ti's simply not there, I get an error if I try to use it. Any ideas why this is so? Do those strings have length limitations? Can they only consist of a single line? If that's the case, what's the right place to put my SQL create script? Thanks for your answers.

2
  • Can we assume app_name and hello are both working? Commented Oct 12, 2011 at 21:27
  • Are you using Eclipse? Have you tried a clean up? Commented Oct 12, 2011 at 21:27

1 Answer 1

2

R.string.create_database in the generated R is an integer (see your line with the comment). In order to get the string value, you need to call getString(R.string.create_database). See getString(int)

Sign up to request clarification or add additional context in comments.

4 Comments

OK I've tried that. First of all, as I said, there's no 'create_database' in 'R.string'. It's just NOT THERE. Secondly, what object am I supposed to call the getString method on?
the 'create_database' not being there has just been resolved, somehow the IDE imported Android.R, and so my code didn't find my own R. Stilly trying to figure out how to squeeze the string value ouf of it lol.
context.getString(R.string.create_database); hallelujah :)
Sorry, I may have overlooked that part after your DATABASE_CREATE line. Yes, the import makes sense and that does happen sometimes... If you're using Eclipse, Ctrl/CMD+Click the variable (create_database) and it brings you to the value in R.string, then your import is probably wrong. Also, Ctrl/CMD+Shift+O is "Organize Imports" in Eclipse, which may figure that out automatically.

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.