2 つの問題があります。
x.substring(i,1)の休憩try/catchそれとおそらく他の理由で、このメソッドを機能させることができません。
max lengthユーザーが小数を入力すると、のEditTextが増加しますが、ユーザーが大きすぎる数値を入力するmax lengthと元に戻るようにしようとしています。max lengthboolean tooBig = false; EditText txt = (EditText)findViewById(R.id.num1); TextView display = (TextView)findViewById(R.id.display); String x = txt.getText().toString(); // the String in the EditText String str = "didn't work"; try { if (x.contains(".")) { // set the max length to be 15 if (x.length() >= 10) { // see if the decimal is contained after 10 digits for (int i = 10; i < x.length(); i++) { str = x.subtring(i,1); // breaks here (test) if (x.substring(i,1).equals(".")) // also breaks here { tooBig = true; } } } if (tooBig) { // set text to be blank and max length to be 8 } } } catch (Exception e) { txt.setText(str); // "didn't work" }
x.substring(i,1)この問題を解決するにはどうすればよいですか?