Android/Java changing TextViews text by inputting String id's HELP!
Well as the title states, anytime I try (in my java class) to settext of a TextView by directing it set the text of a string listed in "strings.xml" my program crashes, If i remove that call then the program runs fine. Below is an example.
MediaPlayer dus;
String Stat;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
final TextView T = (TextView) findViewById(R.id.Status);
dus = MediaPlayer.create(DialUpDroidActivity.this, R.raw.dus);
Timer timer;
timer = new Timer();
dus.start();
Stat = getString(R.string.Dial);
TimerTask TxtTimer = new TimerTask() {
public void run() {
T.setText(Stat);
}
};
timer.schedule(TxtTimer, 7000);
}
So as you can see i tried to do T.setText(Stat); but the program crashed. I've tried T.setTextView(R.string.Dial); and T.setTex开发者_运维知识库tView("Hello") Both methods crashed. What am I doing wrong?
Have you initiliazed your textview?
TextView T = (TextView)findViewById(R.id.yourId);
Where is
T = (TextView)findById(...)
? Use
getString(R.string.XXX)
精彩评论