null pointer exception
Eric <[email protected]>
| Newsgroups | gmane.comp.jakarta.bcel.user |
|---|---|
| Message-ID | <[email protected]> |
The following program when run throws a null pointer exception from the
call to MethodGen.getMethod (the stac trace says it is
LocalVariableGen.getLocalVariable which is called by
MethodGen.getLocalVariableaTable). Can anyone help?
clazz = new ClassGen("Program", "java.lang.Object", "<generated>",
Constants.ACC_PUBLIC | USE_INVOKESPECIAL_SEMANTICS,
IMPLEMENTS_NO_INTERFACES);
constantPool = clazz.getConstantPool();
instructions = new InstructionList();
mainMethod = new MethodGen(Constants.ACC_STATIC | Constants.ACC_PUBLIC,
Type.VOID,
new Type[]{new
ArrayType(Type.STRING, ONE_DIMENSIONAL)},
new String[] {"args"},
"main", "Program",
instructions, constantPool);
factory = new InstructionFactory(clazz);
Instruction i = factory.createFieldAccess("java.lang.System", "out", new
ObjectType("java.io.PrintStream"),
Constants.GETSTATIC);
instructions.append(i);
instructions.append(new PUSH(constantPool, "Hello");
instructions.append(factory.createInvoke("java.io.PrintStream", "print",
Type.VOID,
new Type[]{Type.STRING}, Constants.INVOKEVIRTUAL));
instructions.append(InstructionConstants.RETURN);
mainMethod.setMaxStack(5);
clazz.addMethod(mainMethod.getMethod());
instructions.dispose();
clazz.addEmptyConstructor(Constants.ACC_PUBLIC);
clazz.getJavaClass().dump("Program.class");