applet accessing loaded .jar via reflection?

Discussion in 'Java' started by David N. Welton, Mar 12, 2006.

  1. Hi,

    In my applet, I have this:

    public String callMethod(String methodName, String methodArg) throws
    Exception {
    try {
    Class midletClass = midlet.getClass();

    System.out.println("midlet class is " + midletClass);

    Method []ms = midletClass.getMethods();
    for (int i = 0; i < ms.length; i++ ) {
    System.out.println("method: " + ms);
    }

    Method m = midletClass.getMethod(
    methodName, new Class[] { String.class });
    m.invoke(
    midlet, new Object[] { methodArg });

    return "OK";
    } catch (Exception e) {
    String failstr = "Problem calling method '" + methodName +
    "' with argument '" + methodArg + "' \n" + e;
    System.err.println(failstr);
    e.printStackTrace();
    return "FAIL: " + failstr;
    }
    }

    However, it's not printing, or invoking this method, defined in a .jar
    loaded by the first jar:

    public void setScript(String s) { .... }

    It gives a not found error when I try and invoke it, and when I try and
    print it by accessing' midlets with getMethods, it doesn't show it.

    The applet loads the .jar like so:

    Class midletClass;
    try {
    midletClass = Class.forName(midletClassName);
    } catch (ClassNotFoundException ex) {
    System.out.println("Cannot find " + midletClassName + "
    MIDlet class");
    return;
    }

    try {
    midlet = (MIDlet) midletClass.newInstance();
    } catch (Exception ex) {
    System.out.println("Cannot initialize " + midletClass + "
    MIDlet class");
    System.out.println(ex);
    ex.printStackTrace();
    return;
    }


    (Note that it's not actually running in a J2ME environment, despite the
    'midlet' label.)

    I'm out of ideas, more or less...

    --
    David N. Welton
    - http://www.dedasys.com/davidw/

    Linux, Open Source Consulting
    - http://www.dedasys.com/
    David N. Welton, Mar 12, 2006
    #1
    1. Advertising

  2. David N. Welton

    Guest

    David N. Welton wrote:
    .....
    > However, it's not printing, or invoking this method, defined in a .jar
    > loaded by the first jar:
    >
    > public void setScript(String s) { .... }
    >
    > It gives a not found error when I try and invoke it, and when I try and
    > print it by accessing' midlets with getMethods, it doesn't show it.


    What exactly do you mean in this 'not found error'? What is not found?

    Better, where is the URL of your applet?

    (As an aside, I suggest you rewrite your example losing all references
    to 'midlet' - you are not helping people to help you, by introducing
    other
    possibilities that are not related to the problem..)

    Andrew T.
    , Mar 14, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    551
    Arnold Peters
    Jan 5, 2005
  2. Nigel Wade
    Replies:
    2
    Views:
    6,403
    Nigel Wade
    Apr 5, 2005
  3. muttley
    Replies:
    0
    Views:
    2,687
    muttley
    Oct 20, 2005
  4. cyberco
    Replies:
    4
    Views:
    3,720
    Roedy Green
    Feb 14, 2006
  5. Arnold Peters
    Replies:
    0
    Views:
    637
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page