1
我在編輯文本字段時使用if if else。在這個如果編輯文本值大於5比彈出窗口會出現時,我按下提交按鈕,但是當我沒有在edittext字段中輸入任何值比程序將強制關閉並提供錯誤空指針異常如果情況。空指針異常在其他情況下
我的程序如下
EditText name, temp,id_name;
Button submit,display;
ArrayList<NameValuePair> postParameters1 = new ArrayList<NameValuePair>();
String resp=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
name=(EditText)findViewById(R.id.et_nm);
temp=(EditText)findViewById(R.id.temp);
submit = (Button)findViewById(R.id.button1);
submit.setOnClickListener(this);
}
public void onClick(View butt)
{
switch(butt.getId())
{
case R.id.button1:
ds.setName(name.getText().toString());
ds.setTemp(temp.getText().toString());
if(temp > 5)
{
tv1=new TextView(this);
tv1.setText(" Temp is High");
Dialog(tv1);
}
}
....
....
能否請您澄清退出文本你所談論的,在其他條件,也請您縮進代碼,使其更具可讀性。 – xbonez
哪裏是'困難1'和'preg'帖子相關代碼 –
什麼是DS?請檢查Android初學者博客。 –