android - Problems with calling from strings.xml -


i having problem calling string values strings.xml resource in android. strings.xml file below:

<?xml version="1.0" encoding="utf-8"?> <resources>     <string name="name1">contact_name1</string>     <string name="phone1">contact_phone1</string> </resources> 

and code calling string values is:

private final string name1  = getstring(r.string.name1); private final string phone1 = getstring(r.string.phone1); 

i calling strings main.java extend activity, have context. problem when run app (physical device (evo) or emulator (api levels 5 - 8) nullpointerexception @ line first getstring() call located. have been on google's documentation, number of posts here , @ anddev.org no change end result. 1 please tell me whats wrong before pull of hair out!? strings.xml file in standard location (<project_folder><res><values> directory) in same package rest of app.

you can't call getstring in effect constructor of activity context not exist. need remove final keyword , assign member variables in oncreate().


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -