-2

To avoid adding problem with which value should I init the value of rule_prio ? ...1) rule_prio.add(int x , Rule r) doesn't work too; 2)initializing it with an existing EList doesn't work too 3) is temp.remove(int) is really deleting the value or modify only the pointer ????

    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;
  }

Or it could be rule model the problem ?

Arvel
  • 19
  • 1
  • 2
  • What is an "EList"? And which line exactly causes the NPE to be thrown? Have you tested the variables on that line to find out which one is null? Do you know the general principles of how to debug NPE's? – Hovercraft Full Of Eels May 07 '16 at 19:37
  • show your stacktrace and show, what line of code caused the NullPointerException –  May 07 '16 at 19:37
  • the line rule_prio.add(temp.get(p)); and no i don't anything about debugging NPE's – Arvel May 07 '16 at 19:40
  • EList ...Ecore List, all type prefix are E..., EFloat, EInt .... – Arvel May 07 '16 at 19:47

1 Answers1

2

is the initial value null of rule_prio the problem

for sure it is... if you declare

EList<Rule> rule_prio = null; 

and then do this:

rule_prio.add(temp.get(p));

it makes sense that you get a NPE...

you have to init the EList how ever that object is initialized...

EList<Rule> rule_prio = ...//init the EList here; 
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97