OT: This is for java geeks out there
Christoph Höger
choeger at cs.tu-berlin.de
Fri Sep 5 11:38:15 UTC 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Andrew Haley schrieb:
> Christoph Höger wrote:
>> Hi,
>>
>> I do not know where to ask that, so I try it here:
>>
>> I want to load a (dynamically created) class via URL ClassLoader and
>> then invoke a public static method on it.
>>
>> Here is the code:
>>
>> Class lexerDefs = Class.forName("parser.LexerDefs", true, loader);
>>
>> Method getLexerDefs = null;
>>
>> try {
>> getLexerDefs = lexerDefs.getMethod("lexerDefs", new Class[] {});
>> } catch (NoSuchMethodException e) {
>> fail("Class " + lexerDefs.getName() + " has no method lexerDefs()\n"
>> + e.getMessage());
>> }
>>
>> parser.Options.inputFile = this.inputFile;
>>
>> System.err.println("invoking: " + getLexerDefs.toString());
>>
>> Object retObject = getLexerDefs.invoke(null, new Object[0]);
>>
>> But all I get is:
>> Class test.TestParserGenerator can not access a member of class
>> parser.LexerDefs with modifiers "public static"
>>
>> So loading class seems to work, but I cannot invoke a _public_ method? Why?
>>
>> Anyone knows about reflection?
>
> Yes. Does a public static method with that exact signature "()" exist?
> In the classpath? What if you call it directly?
>
> Andrew.
>
Hi,
the problem is solved (thanks again to Alexei Mokeev who answered off
list). My external class wasn't public enough ;).
The error message confused me, as it stated it could not access the
method and not the class.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFIwRonhMBO4cVSGS8RAiPrAKC9JiH5PlWyKayfyGP2E5fnUK+b4wCcDJqt
eZiZncqIz31roLe335NUy0k=
=wM50
-----END PGP SIGNATURE-----
More information about the fedora-devel-list
mailing list