Menu

Talk to midlet via applet with javascript

2006-03-12
2013-04-26
  • David N. Welton

    David N. Welton - 2006-03-12

    Hi,

    As you may know, it's possible to 'talk to' an Applet via Javascript.  I'd like to be able to do this with my MIDlet.  One way would be to use the Method type and do something like this in javascript:

    foo = document.getElementById("appletid");
    foo.callMethod("midletMethodName", "string argument");

    This would use 'callMethod' implemented in Main.java, which would then dispatch on the arguments it received.

    What do you think?

    Thanks,
    Dave

     
    • David N. Welton

      David N. Welton - 2006-04-01

      I can't figure out why, but it doesn't seem to work.  It doesn't recognize methods I put in my MIDlet:

      java.lang.NoSuchMethodException: Hecl.runScript(java.lang.String)

      I'm attempting to invoke it like so:

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

      from within Main.java in the microemulator code.

      In my MIDlet, runScript is done like this:

          public void runScript(String s) {
          try {
              interp.eval(new Thing(s));
          } catch (Exception e) {
              System.err.println("Error in runScript: " + e);
          }
          }

      So I'm really at a loss as to why microemulator can't see it...

       
      • David N. Welton

        David N. Welton - 2006-04-01

        What's odd is that if I go fishing for what methods *are* available, I get the main MIDlet ones:

        method: public void Hecl.startApp()
        method: public void Hecl.pauseApp()
        method: public void Hecl.destroyApp(boolean)
        method: public void Hecl.exitApp()
        method: public final void javax.microedition.midlet.MIDlet.notifyDestroyed()
        method: public final java.lang.String javax.microedition.midlet.MIDlet.getAppProperty(java.lang.String)
        method: public final void javax.microedition.midlet.MIDlet.notifyPaused()
        ...
        ...

        Very weird.

         
    • Bartek Teodorczyk

      It could be a problem with classloader. Could you prepare code snippet MIDlet that I could easily reproduce your problem and try to isolate the problem.

      Bartek

       
      • David N. Welton

        David N. Welton - 2006-04-10

        Seems like there was something else going wrong, as I cleaned up my whole environment and started from scratch.  Things started working, so I guess it's not a problem afer all...

         

Log in to post a comment.

MongoDB Logo MongoDB