Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

applet accessing loaded .jar via reflection?

Thread view: 
David N. Welton - 13 Mar 2006 00:19 GMT
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[i]);
       }

       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...

Signature

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

Linux, Open Source Consulting
- http://www.dedasys.com/

andrewthommo@gmail.com - 15 Mar 2006 00:34 GMT
....
> However, it's not printing, or invoking this method, defined in a .jar
> loaded by the first jar:
[quoted text clipped - 3 lines]
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.