0
votes

This is my code;


String KLMN = isekle_dosyaucreti.getText().toString(); if (!KLMN.contains(",")) {

        KLMN = KLMN + ",00";
        Toast.makeText(getApplicationContext(), KLMN, Toast.LENGTH_SHORT).show();

    }
    else if(KLMN.contains(",")){

        String[] data = KLMN.split(",", 2); //before comma
        String[] xab = KLMN.split(",");
        String nn = xab[0];
        String mm = xab[1]; // after comma

        if(mm.length() < 2) {
            KLMN = data[0].concat("," + mm).concat("0");
            Toast.makeText(getApplicationContext(), KLMN, Toast.LENGTH_SHORT).show();
        }

        else if(mm.length() == 2) {
            KLMN = data[0].concat(","+xab[1]);
            Toast.makeText(getApplicationContext(), KLMN, Toast.LENGTH_SHORT).show();
        }

        else if(mm.length() > 2) {
            Toast.makeText(getApplicationContext(), "The number after the strike cannot be larger than 2 digits", Toast.LENGTH_SHORT).show();
        }

        else if(mm.length() == 0) {
            Toast.makeText(getApplicationContext(), "Should be after the vigrul", Toast.LENGTH_SHORT).show();
        }

    }

<

--------- This is the error: beginning of crash

2020-04-11 23:04:33.560 609-609/com.nicatalibli.bilirkisiasistanti E/AndroidRuntime: FATAL EXCEPTION: main Process: com.nicatalibli.bilirkisiasistanti, PID: 609 java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 at com.nicatalibli.bilirkisiasistanti.Activity.BottomActivity.isekle.Deneme(isekle.java:1422) at com.nicatalibli.bilirkisiasistanti.Activity.BottomActivity.isekle.onClick(isekle.java:1462) at android.view.View.performClick(View.java:6597) at android.view.View.performClickInternal(View.java:6574) at android.view.View.access$3100(View.java:778) at android.view.View$PerformClick.run(View.java:25885) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Error line;

String mm = xab[1]; >

1

1 Answers

0
votes

Length=1 means array have only one element and that is at 0th position, because array starts with 0th position and you are accessing 1st(index=1) position element from array or doing some operation on 1st position. That is what error indicates. in KLMN there is no any digit after "," and that is why there is not xab[1] element which you are trying to access. Now debug your code and check for the real length of the array(tab).