how to change the string values of sting.xml file
i hava a layout file like test.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/test_string" />
</RelativeLayout>
and java file like this. test1.java
public class test1 extends Activity {
String t开发者_Go百科emp="This is String"; //which change dynamically
TextView tempview;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tempview=(TextView)findViewById(R.id.test_string);
tempview.setText(temp);
setContentView(R.layout.test);
}
}
what i am trying to do is show the value of temp in activity as above code. but it throws an NullPointerException
. so how to do. how to set the values of sting.xml???
thanks in advance..
setContentView(R.layout.test);
should come before (TextView)findViewById(R.id.test_string);
精彩评论