java.lang.NumberFormatException:无效的int:""错误

时间:2014-08-04 15:07:37

标签: java android

protected void onCreate(Bundle savedInstanceState){

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ayak1=(EditText) findViewById(R.id.editText1);      
    say1 = Integer.parseInt(ayak1.getText().toString());
    button1=(Button) findViewById(R.id.button1);        
    button1.setOnClickListener(this);


}


@Override
public void onClick(View v) {
    if(v==button1){
        int sonuc=(say1)*(6)/(10);
        String total = String.valueOf(sonuc);
        fiyat.setText(total);
    }

这是代码,你能帮忙吗?

1 个答案:

答案 0 :(得分:3)

您的ayak1.getText().toString()字符串为空。如果你向它传递一个空字符串(或任何无法解析为int的字符串),Integer.parseInt()会给你NumberFormatException