applet accessing loaded .jar via reflection?

D

David N. Welton

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/
 
A

andrewthommo

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top