线程“main”中的异常 java.lang.Error:未解决的编译问题:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19912958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 21:15:28  来源:igfitidea点击:

Exception in thread “main” java.lang.Error: Unresolved compilation problems:

javaeclipseexist-db

提问by Suresh

Whenver I run this program, its always throwing this error

每当我运行这个程序时,它总是抛出这个错误

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

And while I was trying run this code in Eclipse IDE it's telling me

当我尝试在 Eclipse IDE 中运行此代码时,它告诉我

declared package org.exist.examples.xmldb does not match the expected package

When I compile it it's throwing the error at Put.main(Put.java:27)

当我编译它时,它在 Put.main(Put.java:27) 处抛出错误

package org.exist.examples.xmldb;

import java.io.File;

import org.exist.xmldb.XmldbURI;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
import org.xmldb.api.base.Database;
import org.xmldb.api.modules.CollectionManagementService;
import org.xmldb.api.modules.XMLResource;

/**
 * Add a document to the database.
 * 
 * Call with java -jar start.jar org.exist.examples.xmldb.Put collection docName
 *
 */
public class Put {

    public final static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";

    protected static void usage() {
        System.out.println("usage: org.exist.examples.xmldb.Put collection docName");
        System.exit(0);
    }

    public static void main(String args[]) throws Exception {
        if(args.length < 2)
            usage();

        String collection = args[0], file = args[1];

        // initialize driver
        String driver = "org.exist.xmldb.DatabaseImpl";
        Class<?> cl = Class.forName(driver);            
        Database database = (Database)cl.newInstance();
        database.setProperty("create-database", "true");
        DatabaseManager.registerDatabase(database);

        // try to get collection
        Collection col = 
            DatabaseManager.getCollection(URI + collection);
        if(col == null) {
            // collection does not exist: get root collection and create.
            // for simplicity, we assume that the new collection is a
            // direct child of the root collection, e.g. /db/test.
            // the example will fail otherwise.
            Collection root = DatabaseManager.getCollection(URI + XmldbURI.ROOT_COLLECTION);
            CollectionManagementService mgtService = 
                (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
            col = mgtService.createCollection(collection.substring((XmldbURI.ROOT_COLLECTION + "/").length()));
        }
        File f = new File(file);
        // create new XMLResource
        XMLResource document = (XMLResource)col.createResource(f.getName(), "XMLResource");
        document.setContent(f);
        System.out.print("storing document " + document.getId() + "...");
        col.storeResource(document);
        System.out.println("ok.");
    }
}

回答by Demi

You are trying to run code that does not compile. Eclipse inserts bytecode that throws this error instead.

您正在尝试运行无法编译的代码。Eclipse 会插入引发此错误的字节码。