Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Method injection

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Method injection

    I am invoking a method from a class I obtained by using a URLClassLoader. Which is giving me the following exception.

    java.lang.reflect.InvocationTargetException
    The line that gives this exception is

    public static Object invoked(String aClass, String aMethod, Class[] params,
    			Object[] args) throws Exception {
     
    		Method m = mine.getDeclaredMethod(aMethod, params);
    		Object i = mine.newInstance();
    		Object r = m.invoke(i, args);//this line :(
    		return r;
    	}


    and is called here...

    try {
    				Object a = invoked("Script name", "method4", new Class[] {},
     
    				new Object[] {});
    				boolean b = (Boolean) a;
     
    				return b;
    			} catch (Exception e2) {
    				e2.printStackTrace();
    			}

    Edit: The class name isn't used, avoiding any confusing.

    The method has no parameters either, why is it giving that exception and what does it mean?
    Last edited by java?; December 27th, 2010 at 09:35 PM.
    ohai, java?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,307
    Thanks
    181
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: Method injection

    Its a bit unclear to me what the context is here, what is mine? Passing a regular object to the reflection method will not give you access to a method named 'method4'. Might be best to post a short, compilable, runnable example that demonstrates the problem.

Similar Threads

  1. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM
  2. Dll injection Java
    By TheEnd in forum Java Theory & Questions
    Replies: 1
    Last Post: March 2nd, 2010, 03:35 PM
  3. Object Injection
    By Json in forum Java Programming Tutorials
    Replies: 1
    Last Post: December 4th, 2009, 03:08 AM