我有两个问题:
x.substring(i,1)
中断try/catch
由于这个以及可能的其他原因,我无法让这种方法起作用。我试图拥有它,所以当用户输入小数时,它会增加 的
max length
,EditText
但如果用户输入的数字太大,则会减少max length
回原来的值。max length
boolean 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)
问题?