4drenaline
4drenaline

Reputation: 55

Javascript to Java Applet Uncaught TypeError: Object #<HTMLAppletElement> has no method

This is a example from http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html I have stripped out a lot of the functionality because I am just trying to get basic applets to work but even when I run their example straight out of the zip it gives me an error saying enter image description here I have also tried archiving the classes into a jar file to see if that helps but it still continues to give me the same error.

I think the problem is the folder/file structure but I am not sure.

JavaScript and HTML

<script>
function enterNums(){
mathApplet.userName = "John Doe";
var greeting = mathApplet.getGreeting();
}
</script>
    <script src="http://www.java.com/js/deployJava.js"></script>
<script>
  var attributes = { 
    id:'mathApplet', 
    code:'jstojava.MathApplet',  
    width:1, 
    height:1
  } ;
  var parameters = { 
    codebase:"/scripts/java/", 
    jnlp_href:"math_applet.jnlp"
  } ;
  deployJava.runApplet(attributes, parameters, '1.7');
</script>
<p><a href="javascript:enterNums();">Launch Example</a></p>

JNLP File

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+">
<information>
    <title>Math Applet - JavaScript to Java LiveConnect</title>
    <vendor>Sun</vendor>
</information>
<resources>
    <!-- Application Resources -->
    <j2se version="1.6+"
          href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="jstojava.jar" main="true" />

</resources>
<applet-desc 
     name="Math Applet"
     main-class="MathApplet"
     width="1"
     height="1">
 </applet-desc>
 <update check="background"/>
</jnlp>

Java Code

package jstojava;
import java.applet.Applet;

public class MathApplet extends Applet{
  public String userName = null;

  public String getGreeting() {
    return "Hello " + userName;
  }
}

Upvotes: 1

Views: 3262

Answers (1)

4drenaline
4drenaline

Reputation: 55

So after realizing you can turn up the error tracing in the Java Console Control Panel>Java>Advanced>Show Console

In Console press 5 to set highest trace level.

It turns out that the jnlp file isn't being downloaded due to the fact that mime type isn't allowed on the webserver.

Upvotes: 1

Related Questions