• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mac-specific applet-Javascript communication problem

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

We just recently refactored some code in an applet that was written in Java 1.4. I confirmed that the Java 1.6 version of the applet runs fine within X11 on my Mac. However, when I try to call the applet within a Web page with the following invocation:



on my Mac, I get an error, "Result of expression 'document.responseApplet.setMol' [undefined] is not a function." This happens on both Safari 5 and Firefox 3. However, in Firefox on Linux and MSIE on a PC, the applet runs just fine. The Java 1.4 version of the applet also runs just fine on my Mac. So the problem is Mac-specific and specific to the new version of the applet. Any ideas?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's quite possible that different Java Plugin versions handle the timing of applet initialization differently. I would in any case shy away from using JavaScript to access elements of the page DOM tree before the page is fully realized. Try moving the script into a method that's called from the BODY's onLoad handler.
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tip, Ulf. I tried what you said: I moved the setMol() call into its own function, and I call that function in the body onload property. Unfortunately, I get the same error.

Here's an interesting tidbit: The Post reply and Quote buttons on this very forum don't work in Safari, either! I'm writing this reply in Firefox.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quite a few people use these forums with Mac Safari, so I know that in general there's nothing wrong with it. In fact, I switched to Mac Safari for this very post, and "Post Reply" works fine, as is the Quote button.

Hmm, maybe there's an issue with your browser? Do you have access to a different Mac (preferably with a different OS/Safari/Java version) to test?
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My bad, I needed to log in again before the buttons became active. Red herring, sorry about that.

But I did find out that on a MacOS 10.3.9 computer, both Safari 1.3 and Firefox 2.0 also failed to load the aforementioned Java 1.6 applet.

Here's some more information. The problem has nothing to do with the setMol() command. I've set up a very simple Web page here that invokes the Java 1.6 applet, and it fails to load on Safari for Mac but loads fine on IE. The same page here here invokes the Java 1.4 applet just fine in Safari. The only difference between the two files is the path to the applet, but that can't be the problem because PC and Linux browsers load the Java 1.6 applet just fine.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what you mean by "the Java 1.6 applet" and "the Java 1.4 applet", since neither applet specifies which Java version should be used to run it. So the browser would choose the default JRE set up on the client machine.

(Both applets work fine on my Mac Safari instance, BTW, on a machine that uses Java 5 as the default.)
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The old version of the Java applet was written in and compiled with Java 1.4. The new version was written in and compiled with Java 1.6. The old version ran fine on all browsers. The new version ran fine on PCs and Linux machines, but not on Macs.

At my suggestion, my colleague downloaded Java 1.5 onto our machine earlier today and used it to recompile the applet. This version of the applet runs fine on my Mac. (Ulf, he did this at 5:24 pm EDT, and it looks you posted your message at 5:51 pm EDT, so it's quite possible you got the Java 1.5 version, and that's why it worked for you.)

So the lesson appears to be as follows: Applets compiled with a Java 1.6 compiler may not run properly on Macs when delivered through a browser. I found some intimations of this problem on the Web, which is how I got the idea of recompiling the applet in Java 1.5.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

So the lesson appears to be as follows: Applets compiled with a Java 1.6 compiler may not run properly on Macs when delivered through a browser. I found some intimations of this problem on the Web, which is how I got the idea of recompiling the applet in Java 1.5.


The "may not run properly" part probably depends on which OS X version is used. Earlier you mentioned OS X 10.3, which doesn't support Java 5 or Java 6. And OS X 10.4 does not support Java 6. See http://developer.apple.com/mac/library/technotes/tn2002/tn2110.html for all the gory details.

(I have just added a link to that Tech Note to the MacOsxFaq.)
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Java 1.6-compiled applet failed on browsers running MacOS 10.5.8 as well. But your point about OS 10.3 is well taken. I'll have to test our Java 1.5-compiled applet on a MacOS 10.3 browser.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The Java 1.6-compiled applet failed on browsers running MacOS 10.5.8 as well.


Keep in mind that just because an OS X version supports a certain Java version does not mean that that Java version is set as the default version to use. In particular, I seem to remember that the default version on OS X 10.5 is Java 5. You can use /Application/Utilities/Java Preferences.app to examine (and alter) the default version to use, separately for applets and desktop apps.
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On both my computers, my Java preferences panel is set to use 32-bit J2SE 5.0 first, 64-bit Java SE 6 second, and 64-bit J2SE 5.0 third. So I don't think that's the issue here. However, you raise a good point: We don't want users to have to fiddle with their Java preferences in order to get the applet to work.

That document you pointed me to looks to be very helpful, especially the part about,

javac -source 1.6 -target 1.4 *.java

It might allow us to program and compile in Java 1.6 but still be compatible with MacOS browsers, even MacOS 10.3. I'll try it and see.
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We tried recompiling the code to Java 1.4 target. We get these errors:

javac: source release 1.6 requires target release 1.6 [using 1.6]
javac: source release 1.5 requires target release 1.5 [using 1.5]

Any ideas?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The -source and -target parameters must be the same.
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought the whole point was to compile code written for later Java into a form that could be read by earlier Java?
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, here's a bit more information. The Java console is now giving a little more information when I load http://epoch.uky.edu:9080/epoch-plugin/public/lewisTest.jsp :

basic: Exception: java.lang.UnsupportedClassVersionError: Bad version number in .class file

Except that from what I can tell, this error occurs when the applet is compiled in a later version of Java and the user has only an earlier version of Java. But I have the later version! And X11 on my computer can run the Java 1.6-compiled applet just fine. It's just the Web browsers that won't run the applet.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bob Grossman wrote:I thought the whole point was to compile code written for later Java into a form that could be read by earlier Java?


It is. But you need to ascertain that the source is actually compatible with the target (even though it may not be, for example if you're using Java 6-only methods). (Don't try to apply reason :-)
 
reply
    Bookmark Topic Watch Topic
  • New Topic