当我为此处的代码输入 1 个字母时,出现错误“线程“主”java.lang.StringIndexOutOfBoundsException 中的异常:字符串索引超出范围:1”我该怎么办?
static void addSchool() throws IOException {
System.out.print("Enter Name of School: ");
bName = br.readLine();
bName1= bName.charAt(0);
bName2= bName.charAt(1);
System.out.print("Enter Address of School: ");
bAdd = br.readLine();
System.out.print("Enter Name of Pricipal: ");
pName = br.readLine();
System.out.print("Enter Number of Students: ");
nOS = Integer.parseInt(br.readLine());
newSchool = new School(bName, bAdd, pName, nOS);
prev = null;
curr = list;
if(curr != null && bName1 > curr.getItems()){
while (curr != null && bName1 == curr.getItems())
prev = curr;
curr = curr.getNext();
}
if (curr != null && bName2 > curr.getItemss()){
while(curr != null && bName2 == curr.getItemss())
prev = curr;
curr = curr.getNext();
}
}