简体   繁体   中英

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

I'm currently working with Apache Jena. Actually i try to understand all tutorial that Apache Jena provide and found error like this on Tutorial06 -->

Exception in thread "main" org.apache.jena.shared.PropertyNotFoundException: http://www.w3.org/2001/vcard-rdf/3.0#N at org.apache.jena.rdf.model.impl.ModelCom.getRequiredProperty(ModelCom.java:1281) at org.apache.jena.rdf.model.impl.ResourceImpl.getRequiredProperty(ResourceImpl.java:173) at belajar.Tutorial06.main(Tutorial06.java:38) C:\\AppData\\Local\\NetBeans\\Cache\\8.2\\executor-snippets\\run.xml:53: Java returned: 1 BUILD FAILED (total time: 2 seconds)

Code:

 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());
        }
    }
}

Please help me

The URI you are querying for has a missing back slash.

The current line in the tutorial:
static final String johnSmithURI = "http://somewhere/JohnSmith";

A line that you could replace it with:
static final String johnSmithURI = "http://somewhere/JohnSmith/";

This is what is defined in the provided file, vc-db-1.rdf, I don't believe there is a requirement for a / at the end of URIs or anything. You could also change the URI in vc-db-1.rdf and it should work just as good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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