java.lang.StringIndexOutOfBoundsException: String index out of range: 0
我是用hibernate做表关联映射!
用
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
自动建立了表格!但在运行的时候就爆出java.lang.StringIndexOutOfBoundsException: String index out of range: 0异常 我不明白这问题出在哪里了!关联映射无非就是配置!报这错我实在搞不明白!请前辈指点!
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
答案:2 悬赏:80
解决时间 2021-03-21 09:34
- 提问者网友:月葬花瑰
- 2021-03-20 19:27
最佳答案
- 二级知识专家网友:一池湖水
- 2021-03-20 19:41
数组下表越界了的,就说明你配置有错,在程序中不能识别
全部回答
- 1楼网友:高冷不撩人
- 2021-03-20 19:53
string index out of range: -1 这是越界了,应是str.indexof("+")出错。string 的indexof方法返回查找字符在字符串中的位置,但是没找到的话就会返回-1(详细看jdk api文档)。所以当找不到指定字符时救会出错了,字符串下标从0到str.length(),来个-1自然越界(substring()方法)。
最好在处理前做个判断
int index = str.indexof("+");
if(index!=-1){
op2=double.parsedouble((str.substring(index,str.length())));
}else
{
system.out.println("找不到指定字符!");
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯