setText()方法在我的應用程序中返回null爲什麼?textView.setText();崩潰
public class GetValue extends Activity {
char letter = 'g';
int ascii = letter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView)findViewById(R.id.txt_1);
textView.setText(ascii);
}
}
不管我放什麼文本,它總是崩潰。爲什麼setText()保持返回null?
謝謝你,提前
解決方法:在xml文件我的錯誤。我寫道: 機器人:文本= 「@ + ID/txt_1」 當它應該說: 機器人:ID = 「@ + ID/txt_1」
非常感謝所有的答案,評論!
你肯定的伎倆,即TextView的是不是空了嗎?你能提供一個錯誤信息嗎? – janoliver 2011-03-15 21:53:46
可能findViewById()不起作用。你確定你定義了一個叫做txt_1的TextView嗎? – RoflcoptrException 2011-03-15 21:54:00
發佈您的main.xml文件。 – 2011-03-15 21:56:47