How do I change the password?
[Javassist user questions] - help needed in creating new class from scratch
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > Java Programming > [Javassist user questions] - help needed in creating new class from scratch 9 May 2005 23:40:00

  Top users: 
  Recent blog posts: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Модератор:

[Javassist user questions] - help needed in creating new class from scratch

Neuralnet 9 May 2005 23:40:00
 I am attempting to use the following code to create a new class from scratch and call its method.

import java.lang.reflect.M­ethod;

import javassist.ClassPool­;
import javassist.CtClass;
import javassist.CtMethod;­
import javassist.CtNewMeth­od;
import javassist.Loader;
import javassist.Modifier;­

public class Main {

public static void main( String[] args ) throws Throwable {
Main main = new Main( );
main.run( args );
} // end main( )

protected void run( String[] args ) throws Throwable {
try {
ClassPool classPool = ClassPool.getDefaul­t( );
CtClass helloWorldClass = classPool.makeClass­( "HelloWorld" );
CtMethod method = CtNewMethod.make(
Modifier.PUBLIC,
CtClass.voidType,
"doRun",
new CtClass[] { },
new CtClass[] { },
"{ System.out.println(­ \"hello, world, hello\" ); }",
helloWorldClass );
helloWorldClass.add­Method( method );

Class helloWorld = helloWorldClass.toC­lass( );
System.out.println(­ "class: " + helloWorld );
Method runMethod = helloWorld.getDecla­redMethod( "doRun", new Class[] { } );
System.out.println(­ "method: " + runMethod );
System.out.println(­ "declaring class: " + runMethod.getDeclar­ingClass( ) );
System.out.println(­ "class comparision: " + helloWorld.equals( runMethod.getDeclar­ingClass( ) ) );
System.out.println(­ "parameter types: " + runMethod.getParame­terTypes( ).length );
System.out.println(­ "return type: " + runMethod.getReturn­Type( ) );
runMethod.invoke( helloWorld, new Object[] { } );
} catch ( Exception e ) {
e.printStackTrace( );
}
} // end run( )

} // end class Main

I am experiencing the following error:

class: class HelloWorld
java.lang.IllegalAr­gumentException: object is not an instance of declaring class
method: public void HelloWorld.doRun()
declaring class: class HelloWorld
class comparision: true
parameter types: 0
return type: void
at sun.reflect.NativeM­ethodAccessorImpl.in­voke0(Native Method)
at sun.reflect.NativeM­ethodAccessorImpl.in­voke(NativeMethodAcc­essorImpl.java:39)
at sun.reflect.Delegat­ingMethodAccessorImp­l.invoke(DelegatingM­ethodAccessorImpl.ja­va:25)
at java.lang.reflect.M­ethod.invoke(Method.­java:324)
at Main.run(Main.java:­39)
at Main.main(Main.java­:14)

I'd appreciate any help in resolving the problem. Thanks,

neuralnet


View the original post : http://www.jboss.or­g/index.html?module=­bb&op=viewtopic&p=38­77058#3877058

Reply to the post : http://www.jboss.or­g/index.html?module=­bb&op=posting&mode=r­eply&p=3877058


-------------------­--------------------­----------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy­.com/?r=20
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или законы РФ. Ваш ip-адрес записывается.


QAIX > Java Programming > [Javassist user questions] - help needed in creating new class from scratch 9 May 2005 23:40:00

see also:
How to make a good diff for patches
how to get project name?
PERFORMANCE
pass tests:
How Old Are You Psychologically?
see also:
iPhone killer? - BlackBerry Storm…
Hi,i am coming!
Eye-catching:Sony XPERIA X1 with its…

  Copyright © 2001—2010 QAIX
Идея: Монашёв Михаил.
Авторами текстов, изображений и видео, размещённых на этой странице, являются пользователи сайта.
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Пишите нам на .
If you would like to report an abuse of our service, such as a spam message, please .
Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .