Question

I got this error while intialize the integer,before I use the if to control the integer its fine...but after I add some condition "if" it forced close and in debugger it say error about integer I initialized with parse int...please need help


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;
        }
        }   
    }
Was it helpful?

Solution

You should use a try/catch block for NumberFormatException, like

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

and run that through the debugger

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top