繁体   English   中英

Apache Jena错误:线程“ main”中的异常org.apache.jena.shared.PropertyNotFoundException

[英]Apache Jena Error: Exception in thread “main” org.apache.jena.shared.PropertyNotFoundException

我目前正在使用Apache Jena。 实际上,我尝试了解Apache Jena提供的所有教程,并在Tutorial06中发现了这样的错误->

线程“主要” org.apache.jena.shared.PropertyNotFoundException中的异常:org.apache.jena.rdf.model.impl.ModelCom上的http://www.w3.org/2001/vcard-rdf/3.0#N 。 org.apache.jena.rdf.model.impl.ResourceImpl.getRequiredProperty(ResourceImpl.java:173)处的getRequiredProperty(ModelCom.java:1281)at belajar.Tutorial06.main(Tutorial06.java:38)C:\\ AppData \\ Local \\ NetBeans \\ Cache \\ 8.2 \\ executor-snippets \\ run.xml:53:Java返回:1个失败的日志(总时间:2秒)

码:

 public class Tutorial06 extends Object {

    static final String inputFileName = "vc-db-1.rdf";
    static final String johnSmithURI = "http://somewhere/JohnSmith";

    public static void main (String args[]) {
        // create an empty model
        Model model = ModelFactory.createDefaultModel();

        // use the FileManager to find the input file
        InputStream in = FileManager.get().open(inputFileName);
        if (in == null) {
            throw new IllegalArgumentException( "File: " + inputFileName + " not found");
        }

        // read the RDF/XML file
        model.read(new InputStreamReader(in), "");

        // retrieve the Adam Smith vcard resource from the model
        Resource vcard = model.getResource(johnSmithURI);

        // retrieve the value of the N property
        Resource name = (Resource) vcard.getRequiredProperty(VCARD.N)
                                        .getObject();
        // retrieve the given name property
        String fullName = vcard.getRequiredProperty(VCARD.FN)
                               .getString();
        // add two nick name properties to vcard
        vcard.addProperty(VCARD.NICKNAME, "Smithy")
             .addProperty(VCARD.NICKNAME, "Adman");

        // set up the output
        System.out.println("The nicknames of \"" + fullName + "\" are:");
        // list the nicknames
        StmtIterator iter = vcard.listProperties(VCARD.NICKNAME);
        while (iter.hasNext()) {
            System.out.println("    " + iter.nextStatement().getObject()
                                            .toString());
        }
    }
}

请帮我

您要查询的URI缺少反斜杠。

本教程中的当前行:
static final String johnSmithURI = "http://somewhere/JohnSmith";

您可以将其替换为的行:
static final String johnSmithURI = "http://somewhere/JohnSmith/";

这是提供的文件vc-db-1.rdf中定义的内容,我认为URI或其他内容的末尾不需要/。 您也可以在vc-db-1.rdf中更改URI,它应该也可以正常工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM