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
Post a Comment