为了避免添加问题,我应该初始化rule_prio的值? ... 1)rule_prio.add(int x,Rule r)也不起作用; 2)使用现有的EList初始化它也不起作用3)temp.remove(int)实际上是删除值还是仅修改指针????
private static EList<Rule> priorite(EList<Rule> R) {
Rule r;
int min ;
int p=-1;
int last_p = -1;
EList<Rule> rule_prio = null;
EList<Rule> temp = R;
while(temp.isEmpty()==false)
{
min=temp.get(0).getPriority();
for (int i=1; i<temp.size(); i++)
{
r = temp.get(i);
if (r.getPriority() < min)
{
min = r.getPriority();
p = i;
}
}
if (p!= -1 && p!= last_p)
{
rule_prio.add(temp.get(p));
temp.remove(p);
last_p = p;
}
}
return rule_prio;
}
或者它可能是规则模型的问题?
答案 0 :(得分:2)
是rule_prio的初始值null
肯定是......如果你宣布
EList<Rule> rule_prio = null;
然后执行此操作:
rule_prio.add(temp.get(p));
你得到NPE是有意义的......
你必须初始化 EList 该对象的初始化...
EList<Rule> rule_prio = ...//init the EList here;