You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Eric <ee...@ukfsn.org> on 2004/08/31 16:53:30 UTC
null pointer exception
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");
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org