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

开发实习生 2017-04-14 06:40:14


//向服务器获取根目录
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(), "网络异常,请稍后再试");
}
相关的代码贴出来了,但不是很理解这个数组怎么就越界了。也不知道怎么去修改
...全文
2159 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
changerzhuo 2017-04-16
  • 打赏
  • 举报
回复
inputstream读取到文件末尾的时候, 会返回-1的
这是一个维护版本,主要是bug修复: ** Bug * [MNG-4840] - Prerequisites is not working on m3 * [MNG-4913] - [regression] User properties override equally named POM properties of transitive dependencies * [MNG-4915] - Versions in pom.xml are not checked for invalid characters * [MNG-4918] - MavenProject#clone() doubles active profiles * [MNG-4919] - Plugin execution contributed by lifecycle mapping gets lost when same goal is bound multiple times * [MNG-4923] - [regression] java.lang.ClassNotFoundException: org.apache.maven.artifact.ArtifactStatus * [MNG-4925] - Mismanagement of container lookup realm can cause type incompatibilities for plugins looking up components by string * [MNG-4933] - With a resource directory as . maven raise an java.lang.StringIndexOutOfBoundsException:217 * [MNG-4941] - PluginDescriptorBuilder doesn't populate expression/default-value fields for mojo parameters * [MNG-4952] - [regression] RELEASE field of repository metadata is not updated upon repeated deployments * [MNG-4955] - [regression] Outdated remote snapshots are preferred over locally installed snapshots * [MNG-4960] - [regression] Make-like reactor mode does not build selected project when resuming from one of its prerequisites * [MNG-4966] - Preserve double slashes in the scm connection url - identifies absolute repository paths for mercurial ** Improvement * [MNG-4912] - Use of raw type should be Comparable * [MNG-4916] - Poor ProjectBuilder.build performance for projects with unresolvable extension plugins * [MNG-4922] - ExecutionEvent give on the exception encountered (when having mojoFailed) * [MNG-4926] - ExecutionEvent give on the exception encountered (when having projectFailed , forkedProjectFailed) * [MNG-4944] - Include JRE vendor in version info * [MNG-4950] - Javadoc improvements to DefaultSettingsWriter/Reader * [MNG-4953] - Issue a warning when a system-scope dependency refers to the project basedir ** New Feature * [MNG-4936] - Allow to better monitor and adjust a Maven build during CI * [MNG-4937] - Allow the platform scripts to avoid loading mavenrc content ** Task * [MNG-4945] - Remove mergeId from public POM * [MNG-4957] - Emit validation warning when project version uses irregular SNAPSHOT version string * [MNG-4959] - Update default plugin versions

50,531

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧