This discussion is archived
8 Replies Latest reply: Jan 3, 2013 3:51 AM by EJP RSS

Static initailizers

880368 Newbie
Currently Being Moderated
Here is some code:

public class A {



public void method1() {


.....
for (IHandlerStrategy strategy : IStrategyContext.fileStrategies) {
//     do some process                    
}

....

}



public class IStrategyContext {

     public static List<IHandlerStrategy> fileStrategies;
public static List<IHandlerStrategy> instStrategies;


     static {
instStrategies.add(new Inst1());
          instStrategies.add(new Inst2());

          for(IlHandlerStrategy instStrategy:instStrategies)
          {
               fileStrategies.add(instStrategy);
          }
}
}


It gives me java.lang.reflect.InvocationTargetException at for (IHandlerStrategy strategy : IStrategyContext.fileStrategies) {

Can someone guide me as to how to resolve the problem. Thank you.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points