如何解决:数字格式异常无效的int:“”

时间:2016-01-10 01:53:26

标签: android

我是Android应用程序开发的初学者。我的代码如下 - 如何解决此代码中的数字格式异常 -

公共类InterestActivity扩展了AppCompatActivity {

        $.ajax({
            type: "POST",
            url: "/Items/Search",
            data: {ItemName, ItemText},
            datatype: "html",
            success: function (data) {
                $('#result').html(data);
            }
        });
   //since data is the HTML partial itself.
   //if you have firebug for Mozilla firefox, you can see what I'm
   //talking about

2 个答案:

答案 0 :(得分:0)

您正在将视图分配给临时局部变量而不是类的属性。

简短解决方案:

EditText

之前删除editAmount = ...

与onCreate中的所有其他作业相同。

如果你想继续进行Android编程,你应该明白为什么会这样。这可能会对您有所帮助:What is the difference between field, variable, attribute, and property in Java POJOs?

答案 1 :(得分:0)

 public void interestCalculate (View v) {
        resultView= (TextView) findViewById(R.id.resultView);
        Calculate = (Button) findViewById(R.id.button4);

        int a = 0;
        int i = 0;
        int d = 0;
        try{
            a= Integer.parseInt(editAmount.getText().toString());
        }catch(Throwable e){
            Toast.makeText(getApplicationContext(),"editAmount"+ "'s value is not a Integer",Toast.LENGTH_LONG);
        }
        try{
            i = Integer.parseInt(editInterest.getText().toString());

        }catch(Throwable e){
            Toast.makeText(getApplicationContext(),"editInterest"+ "'s value is not a Integer",Toast.LENGTH_LONG);
        }
        try{
            d = Integer.parseInt(editDuration.getText().toString());
        }catch(Throwable e){
            Toast.makeText(getApplicationContext(),"editDuration"+ "'s value is not a Integer",Toast.LENGTH_LONG);
        }


        int ir= i/100;

        float res = a*ir*d;
        int intres= (int) res;
        resultView.setText(Integer.toString(intres));
    }}