未被捕获的错误:错误调用方法上NPObject在JavaScript [英] Uncaught Error: Error calling method on NPObject in javascript

查看:238
本文介绍了未被捕获的错误:错误调用方法上NPObject在JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用一个小程序更改的存储库。要做到这一点,我写了下面的code:

I want to use an applet to change a repository. To do this I wrote the following code:

LoadOntology:

LoadOntology:

package owlapi.loader;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.*;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import org.semanticweb.owlapi.util.OWLEntityRenamer;

import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;


public class LoadOntology {
    private static String             ontologyDir   = "./owlapi/loader/featurepool.owl";
    private static OWLOntology        localOntology;
    private static OWLOntologyManager manager;
    private static OWLDataFactory     factory;
    private static PrefixManager      pm            = new DefaultPrefixManager("http://wise.vub.ac.be/Members/lamia/variability/Feature_Assembly/FAM.owl#");

public LoadOntology() {
    manager = OWLManager.createOWLOntologyManager();
    File file = new File(ontologyDir);
    try {
        localOntology = manager.loadOntologyFromOntologyDocument(file);
        System.out.println("Loaded ontology: " + localOntology);
        factory = manager.getOWLDataFactory();
        }   
    catch (UnparsableOntologyException e) {
        System.out.println("Could not parse the ontology: " + e.getMessage());
        Map<OWLParser, OWLParserException> exceptions = e.getExceptions();
        for (OWLParser parser : exceptions.keySet()) {
            System.out.println("Tried to parse the ontology with the " + parser.getClass().getSimpleName() + " parser");
            System.out.println("Failed because: " + exceptions.get(parser).getMessage());
        }
    }
    catch (UnloadableImportException e) {
        System.out.println("Could not load import: " + e.getImportsDeclaration());
        OWLOntologyCreationException cause = e.getOntologyCreationException();
        System.out.println("Reason: " + cause.getMessage());
    }
    catch (OWLOntologyCreationException e) {
        System.out.println("Could not load ontology: " + e.getMessage());
    }   
}

public void addInstance(String Class, String individual) {
    OWLClass owlClass = factory.getOWLClass(Class, pm);
    OWLClass superClass = factory.getOWLThing();
    OWLIndividual instance = factory.getOWLNamedIndividual(individual, pm);

    OWLClassAssertionAxiom classAssertion1 = factory.getOWLClassAssertionAxiom(superClass, instance);
    manager.addAxiom(localOntology, classAssertion1);
    OWLClassAssertionAxiom classAssertion2 = factory.getOWLClassAssertionAxiom(owlClass, instance);
    manager.addAxiom(localOntology, classAssertion2);
    System.out.println("Instance added");
}
}

InJava(小程序在JavaScript加载):

InJava (applet loaded in javascript):

public class InJava extends Applet{
private static LoadOntology loadedOntology;

public void addInstance(String Class, String individual) {
    Graphics g = getGraphics();
     g.drawString("Test", 10, 10);
    loadedOntology = new LoadOntology();
    loadedOntology.addInstance(Class, individual);
    }
}

当我装入小应用程序,没有错误可言,但是当我尝试调用该方法addInstance:

When I load the applet, there is no error at all, but when I try to call the method addInstance:

<input type="button" value="call Java Applet method" onClick = 'document.owlapi.addInstance("Abstract_Feature", "New_Test")'>
<APPLET CODE="owlapi/InJava.class" NAME="owlapi" HEIGHT=100 WIDTH=100> </APPLET>  

浏览器引发错误未捕获的错误:错误调用方法上NPObject 在计算器阅读一些这方面的问题后,我只是来的,必须有结论有毛病的插件。

The browser throws the error Uncaught Error: Error calling method on NPObject. After reading some questions about this on stackoverflow, I came only to the conclusion that there has to be something wrong with the plugin.

我添加了一些测试 - code的方法,它的工作原理(束带(测试,10,10)),所以我建议LoadOntology类的构建提出了一些问题(这个班是单独测试在作品完美自身)。是否有人看到我做错了吗?

I added some testing-code to the method (the drawString("Test", 10, 10)) which works, so I suggest that the constructing of the LoadOntology class gives some issues (this class was tested separately in works perfect on its own). Does anybody see what I am doing wrong?

更新:的我添加所使用的小程序的Java类的一部分:库加载器。所有提供的code应该编译。

update: I added the a part of the java class that is used by the applet: the repository loader. All the provided code should compile.

更新:的我没有使用 MASCRIPT /脚本化因为code基于的这个例子,这在我的当前浏览器的工作原理(铬)

update: I didn't use MASCRIPT/SCRIPTABLE because the code is based on this example, which works in my current browser (chrome)

UDPATE:的你要包括owlapi罐子到构建路径,它可以下载的此处

udpate: You have to include the owlapi jars to the buildpath, which can be downloaded here

推荐答案

根据我知道的,我建议尝试这种HTML片段。

Based on the fragments I know, I suggest trying this HTML.

<html>
<body>
<APPLET 
    CODE="owlapi.InJava" 
    NAME="owlapi" 
    archive="owlapi/owl1.jar,owlapi/owl2.jar"
    HEIGHT=100 
    WIDTH=100> 
</APPLET>  
</body>
</html>

这个HTML嵌入一个applet'静态' - 不使用JavaScript。在类名( code 属性)应该是类的完全限定名称,而不是文件名。尽管后者通常的耐受性,这是不正确的。它显示了如何导入从 owlapi 目录中的API,根据需要更改名称。

This HTML embeds an applet 'statically' - without using JavaScript. The class-name (the code attribute) should be the fully qualified name of the class, as opposed to the file name. Though the latter is generally tolerated, it is not correct. It shows how to import the API from the owlapi directory, change the names as required.

另外值得关注的是混合宽松的类文件和JAR文件。这往往混淆这两个开发商和JRE。相反,如果 owlapi.InJava 类是把里面的 my.jar ,那罐子放在同一目录下休息, codeBase的可以添加和归档路径更短。像这样的:

Also of concern is mixing loose class files and Jars. This tends to confuse both the developer and the JRE. If instead the owlapi.InJava class was put inside my.jar, and that Jar put in the same directory as the rest, a codebase could be added and the archive paths made shorter. Like this:

<html>
<body>
<APPLET 
    CODE="owlapi.InJava" 
    NAME="owlapi" 
    codebase="owlapi"
    archive="my.jar,owl1.jar,owl2.jar"
    HEIGHT=100 
    WIDTH=100> 
</APPLET>  
</body>
</html>

这是无效的HTML。这仅仅是一个测试,以检查的基础知识。后来,你需要使它有效的HTML和(可能)部署使用 deployJava.js 中的小程序的信息。页

This is not valid HTML. It is just a test to check the basics. Later, you'd need to make it valid HTML and (probably) deploy the applet using the deployJava.js mentioned in the applet info. page.

这篇关于未被捕获的错误:错误调用方法上NPObject在JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆