在项目中遇到这种下标越界的问题怎么改!

z_5201314 2017-09-25 01:31:36
在项目中遇到这种下标越界的问题怎么改!
浏览器报错如下:
java.lang.IndexOutOfBoundsException: Index: 0
at java.util.Collections$EmptyList.get(Collections.java:2976)
at cn.com.gwypx.jwgl.action.staff.RegisterScoreTimeAction.edit(RegisterScoreTimeAction.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:892)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1294)
at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)
at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)

打桩测试action红字部分就没有执行了:
public String edit()
{

List list = TimeService.find();
Map map = (Map) list.get(0);
Integer id = (Integer) map.get("id");
if (!empty(id))
{
scoreTime = TimeService.get(id);
}
if (!empty(scoreTime))
{
request.setAttribute("scoreTime", scoreTime);
}
return "input";
}

public String save()
{

// 首先判断是否存在设置的数据
List list = TimeService.find();
if (list.size() <= 0)
{
// 创建时间
scoreTime.setCreat_date(new Date());

sql:
/*DDL 信息*/------------

CREATE TABLE `tb_register_score_time` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`start_time` date NOT NULL,
`end_time` date NOT NULL,
`status` int(11) DEFAULT '1',
`creat_date` date DEFAULT NULL,
`creat_staff` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
...全文
348 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
李德胜1995 2017-09-25
  • 打赏
  • 举报
回复
list里面没有元素,可以先做非null和size的判断,再get...

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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