onclick按钮中的android错误,它说的是关于整数的东西

时间:2013-09-29 10:46:57

标签: android eclipse button fuzzy

我在初始化整数时遇到了这个错误,在我使用if控制整数之前它很好...但是在我添加一些条件后“if”它强制关闭 并在调试器中它说错误的整数我用parse int初始化...请需要帮助


logcat

09-29 10:58:54.774: D/AndroidRuntime(2512): Shutting down VM
09-29 10:58:54.794: E/AndroidRuntime(2512):     at com.example.fuzzy.Start.onClick(Start.java:89)
09-29 10:58:54.794: E/AndroidRuntime(2512):     at dalvik.system.NativeStart.main(Native Method)
09-29 10:58:54.774: D/AndroidRuntime(2512): Shutting down VM
09-29 10:58:54.794: E/AndroidRuntime(2512):     at com.example.fuzzy.Start.onClick(Start.java:89)
09-29 10:58:54.794: E/AndroidRuntime(2512):     at dalvik.system.NativeStart.main(Native  Method)

public void onClick(View view) {
        // TODO Auto-generated method stub
        switch (view.getId()) {
        case R.id.bnextt:
        Log.d(tag, "masuk button")  ;

            if ( mnp == 0 || mp == 0 
                    || mns == 0 ||ms == 0 || mnpr ==0 || mpr == 0 
                    || nns == 0 || nnp == 0) {

                thasil1.setText("pak bos masih ada yang belum diisi");
                Toast.makeText(Start.this ,"pak bos masih ada yang belum diisi", Toast.LENGTH_SHORT).show();
                Log.d(tag, "kondisi 0");    
            }

            if (mnp > mp ||  mns > ms  
                    || mnpr > mpr  ) {
                thasil1.setText("pak bos min tidak boleh lebih besar dari max");
                Toast.makeText(Start.this ,"pak bos min tidak boleh lebih besar dari max", Toast.LENGTH_SHORT).show();

            }

            if (mnp == mp || mns == ms || mnpr == mpr) {
                thasil1.setText("pak bos min tidak boleh sama dari max");
                Toast.makeText(Start.this ,"pak bos min tidak boleh sama dari max", Toast.LENGTH_SHORT).show();
            }
            if (nns > ms || nns < mns || nnp > mp || nnp < mnp) {

                thasil1.setText("pak bos perbaiki permintaan dan barang sekarang");
                Toast.makeText(Start.this ,"pak bos perbaiki permintaan dan barang sekarang", Toast.LENGTH_SHORT).show();
            }
            else {

                //error in here

                mp = Integer.parseInt(maxp.getText().toString());
                mnp = Integer.parseInt(minp.getText().toString());
                ms = Integer.parseInt(maxs.getText().toString());
                mns = Integer.parseInt(mins.getText().toString());
                mpr = Integer.parseInt(maxpro.getText().toString());
                mnpr = Integer.parseInt(minpro.getText().toString());
                nns = Integer.parseInt(ns.getText().toString());
                nnp = Integer.parseInt(np.getText().toString());
                Log.d(tag, "selesai initialize");


            //fuzzyset1 permintaan
            naikper = (nnp-mnp)/(mp-mnp);
            turunper = (mp-nnp)/(mp-mnp);
            //fuzzyset2 stock
            naikstok = (nns-mns)/(ms-mns);
            turunstok = (ms-nns)/(ms-mns);


            // rules
            r1 = Math.min(turunper,naikstok);
            z1 =( mpr-mnpr)*r1;
            turunpro = mpr - z1;


            }
            thasil1.setText("turunper " + turunper +" naikper " + naikper 
                    + "r1" + r1 + "z1" + z1 + "naikstok" + naikstok + "nns" + nns +
                    "mns" + mns + "ms" + ms);
            Math.round(turunpro);
            thasil2.setText("jumlah produk" + Math.round(turunpro));

            break;
        case R.id.bexit:
            finish();

        default:
            break;
        }
        }   
    }

1 个答案:

答案 0 :(得分:0)

你应该对NumberFormatException使用try / catch块,比如

try {
    x = Integer.parseInt(.....);
    y = Integer.parseInt(.....);
            etc
} catch (NumberFormatException nfe) {
    nfe.printStackTrace();
}

并通过调试器运行