java.lang.StringIndexOutOfBoundsException: String index out of range: -1错误


//向服务器获取根目录
public static String getRootList() throws Exception{
String json = "{\"type\":\"getRootList\"}";
output.write(json.getBytes());
output.flush();
byte[] b = new byte[1024];
int len = input.read(b);
json = new String(b,0,len);//字符串进行转化
Config.ROOT_LIST_JSON_STR = json;
return json;
}

try {
String json_str = Config.service.getRootList();
System.out.println(json_str);
JSONObject json = JSONObject.fromObject(json_str);//对json的解析
JSONArray jsonArray_mulu = json.getJSONArray("mulu");
JSONArray jsonArray_files = json.getJSONArray("files");
this.removeAll();
int count = jsonArray_mulu.size()+jsonArray_files.size();
for (int i = 0; i < jsonArray_mulu.size(); i++) {
JSONObject mulu = jsonArray_mulu.getJSONObject(i);
this.add(new FileJPanel(mulu.getString("rdid"), mulu.getString("did"), "DIR", mulu.getString("dname")));
}
for (int i = 0; i < jsonArray_files.size(); i++) {
JSONObject file = jsonArray_files.getJSONObject(i);
this.add(new FileJPanel(file.getString("did"), file.getString("fid"), "FILE", file.getString("fname")));
}
this.setPreferredSize(new Dimension(508,(count/5+(count%5==0?0:1))*135));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
javax.swing.JOptionPane.showMessageDialog(this.getParent(), "网络异常,请稍后再试");
}
相关的代码贴出来了,但不是很理解这个数组怎么就越界了。也不知道怎么去修改
相关推荐
Spring+Hibernate StringIndexOutOfBoundsException String index out解决方法
Spring+Hibernate运行时所出现的异常Caused by java.lang.StringIndexOutOfBoundsException String index out解决方法
String index out of 4解决方法
String index out of 4解决方法
代码折叠工具 For Eclipse ——修复版
针对此错误的修复版 java.lang.StringIndexOutOfBoundsException: String index out of range: 45 at java.lang.String.charAt(Unknown Source) at com.cb.eclipse.folding.java.calculation.UserDefinedRegionHelper.isSentinel(UserDefinedRegionHelper.java:53) 使用方法如下:http://my.oschina.net/axes/blog/124714 他的jar包是未修复版的。大家可以测试。测试方法:在代码后边直接写两个斜杠,示例如下: private Object mObject;// 就会报我上边贴的错误。
java常见的语法错误
1.变量可能未初始化 错误提示:Abc.java:9: variable i might not have been initialized System.out.println(i); 中文说明:变量i可能没有赋值就使用了。 例子说明: int i; System.out.println(i); 2.变量重复定义 错误提示:Abc.java:9: i is already defined in main(java.lang.String[]) int i = 2; 中文说明:变量重复定义了 例子说明: int i = 1; int i = 2; 3. 找不到符号: Test6.java:26: cannot find symbol symbol : variable j location: class Test6 if(j < 0) { 4. 找不到类的错误 Main.java:4: cannot find symbol symbol : class T1 location: class Main T1 a = new T1();
分析substring(),charAt()等常见java.lang.StringIndexOutOfBoundsException: String index out of range: -1的问题
今天在测试解析`jwt token`时,出现如是错误:java.lang.StringIndexOutOfBoundsException: String index out of range: -1,并列出会出现这种错误的常见方法。


