【发布时间】:2023-04-10 23:18:01
【问题描述】:
这是我的代码;
字符串 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 进程:com.nicatalibli.bilirkisiasistanti,PID:609 java.lang.ArrayIndexOutOfBoundsException:长度=1;索引=1 在 com.nicatalibli.bilirkisiasistanti.Activity.BottomActivity.isekle.Deneme(isekle.java:1422) 在 com.nicatalibli.bilirkisiasistanti.Activity.BottomActivity.isekle.onClick(isekle.java:1462) 在 android.view.View.performClick(View.java:6597) 在 android.view.View.performClickInternal(View.java:6574) 在 android.view.View.access$3100(View.java:778) 在 android.view.View$PerformClick.run(View.java:25885) 在 android.os.Handler.handleCallback(Handler.java:873) 在 android.os.Handler.dispatchMessage(Handler.java:99) 在 android.os.Looper.loop(Looper.java:193) 在 android.app.ActivityThread.main(ActivityThread.java:6669) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
错误行;
字符串 mm = xab[1]; >
【问题讨论】:
标签: android