face++人脸识别出现错误,索引超范围

qq_34001901 2016-05-09 08:55:21
源代码:
new Thread(new Runnable() {
public void run() {
try {

File mfile=new File(Environment.getExternalStorageDirectory()+"/test0");
FileInputStream fis=new FileInputStream(mfile);
int length=fis.available();
byte[] buffer=new byte[length];
fis.read(buffer);
fis.close();

HttpRequests httpRequests = new HttpRequests(constant.KEY, constant.SECRET, true, true);
JSONObject result = httpRequests.detectionDetect(new PostParameters().setImg(buffer));
System.out.println(result);
System.out.println(result.getJSONArray("face").getJSONObject(0).getJSONObject("position").getJSONObject("center"));

} catch (FaceppParseException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}

}).start();



这是错误:
05-09 20:41:11.086 31909-567/com.example.hayden.facepass W/System.err: org.json.JSONException: Index 0 out of range [0..0)
05-09 20:41:11.086 31909-567/com.example.hayden.facepass W/System.err: at org.json.JSONArray.get(JSONArray.java:282)
05-09 20:41:11.086 31909-567/com.example.hayden.facepass W/System.err: at org.json.JSONArray.getJSONObject(JSONArray.java:510)
05-09 20:41:11.086 31909-567/com.example.hayden.facepass W/System.err: at com.example.hayden.facepass.Userface$1$2.run(Userface.java:103)
05-09 20:41:11.086 31909-567/com.example.hayden.facepass W/System.err: at java.lang.Thread.run(Thread.java:841)
求大神解答,非常感谢。

...全文
252 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hoyn 2016-05-11
  • 打赏
  • 举报
回复
很明显json解析出错了。 错误就在这里 result.getJSONArray("face").getJSONObject(0)

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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