为什么我会收到 JDOUserException?

问题描述

我不明白为什么我总是收到 JDOUserException。我得到的错误信息是

Exception in thread "main" [objectdb 2.8.5] javax.jdo.JDOUserException
Failed to create a new file 'C:\Program Files\objectdb-2.8.5\log\odb20210506.log' (error 112)
    at com.objectdb.jdo.PMF.getPersistenceManager(PMF.java:561)
    at com.objectdb.Utilities.getPersistenceManager(Utilities.java:62)
    at CreateData.main(CreateData.java:33)

第 33 行指的是 PersistenceManager 代码行。因此,我无法创建要查看的 odb 文件。我可能做错了什么?我遵循了教授的指导,能够适当地改进课程和所有内容

    `public class CreateData {
     public static void main(String[] args){
        Company c1 = new Company("Apple");
        Company c2 = new Company("Microsoft");
        Company c3 = new Company("Google");
        Company c4 = new Company("Dell");


        OperatingSystem o1 = new OperatingSystem("Windows","001","07/29/2015","10");
        OperatingSystem o2 = new OperatingSystem("MacOS","002","09/24/2018","10.14" );

        cpu cpu1 = new cpu("100","i5","02/01/2020",6,(float) 4.3);
        cpu cpu2 = new cpu("101","i7",8,(float) 4.8);
        cpu cpu3 = new cpu("102","Ryzen Threadripper 3970X","11/25/2019",32,(float) 3.7);
        cpu cpu4 = new cpu("103","M1","03/29/2018",(float) 3.2);

        Memory m1 = new Memory("200","DDR4","04/01/2014",2933);
        Memory m2 = new Memory("201",12,2666);
        Memory m3 = new Memory("202","DDR4 SDRAM",128,3000);
        Memory m4 = new Memory("203","LPDDR3","12/29/2015",2133);

        PC pc1 = new PC("300","Inspiron 3000","03/20/2020",m2,cpu2,o1);
        PC pc2 = new PC("301",m1,cpu1,o1);
        PC pc3 = new PC("302","CLX","01/01/2021",m3,cpu3,o1);
        PC pc4 = new PC("303","MacBook Pro","08/17/2020",m4,cpu4,o2);


        PersistenceManager pm = Utilities.getPersistenceManager("PC.odb");

        pm.currentTransaction().begin();
        pm.makePersistent(c1);
        pm.makePersistent(c2);
        pm.makePersistent(c3);
        pm.makePersistent(c4);

        pm.makePersistent(o1);
        pm.makePersistent(o2);


        pm.makePersistent(cpu1);
        pm.makePersistent(cpu2);
        pm.makePersistent(cpu3);
        pm.makePersistent(cpu4);


        pm.makePersistent(m1);
        pm.makePersistent(m2);
        pm.makePersistent(m3);
        pm.makePersistent(m4);


        pm.makePersistent(pc1);
        pm.makePersistent(pc2);
        pm.makePersistent(pc3);
        pm.makePersistent(pc4);

        pm.currentTransaction().commit();


        Application application1 = new Application("400","Microsoft Word","01/01/2019","2019");
        Application application2 = new Application("401","Microsoft Office","2019");

        pm.currentTransaction().begin();
        pm.makePersistent(application1);
        pm.makePersistent(application2);

        c2.makes.add(application1);
        c2.makes.add(application2);

        o1.supports.add(application1);
        o1.supports.add(application2);
        pm.currentTransaction().commit();


        pm.currentTransaction().begin();
        pc3.memoryTreeSet.add(m1);
        pc3.memoryTreeSet.add(m2);
        pc3.memoryTreeSet.add(m3);
        pm.currentTransaction().commit();
       }
    }
`

解决方法

错误消息表明 ObjectDB 无法在默认路径创建日志文件。尝试以下一项或多项:

  1. 在另一个目录中安装 ObjectDB(或 jar 文件)。
  2. 授予在 C:\Program Files\objectdb-2.8.5 下创建文件和写入的权限
  3. 更改 objectdb.conf 文件中的日志路径。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...