gpt4 book ai didi

java - 错误: Could not find or load main class openWordDocument

转载 作者:行者123 更新时间:2023-12-01 15:16:08 25 4
gpt4 key购买 nike

我正在尝试使用 jacob 打开 Microsoft Word 文档。

下面是代码:

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class openWordDocument {
private static final Integer wdNewBlankDocument = new Integer(0);
private static final Variant vTrue = new Variant(true);
private static final Variant vFalse = new Variant(false);
private static ActiveXComponent activeXWord = null;
private static Object activeXWordObject = null;

public static void main(String[] args) {
try {
activeXWord = new ActiveXComponent("Word.Application");
activeXWordObject = activeXWord.getObject();
Dispatch.put(activeXWordObject, "Visible", vTrue);

//activeXWordObject = null;

}
catch (Exception e) {
quit();
}
}

public static void quit() {
if (activeXWord != null) {
System.out.println("quit word");
//calls the Quit method of MS Word, this will close MS Word
activeXWord.invoke("Quit", new Variant[] {});
ComThread.Release();
activeXWord.release();
System.out.println("quit word");
}
}

}

当我运行上面的代码时出现错误错误:无法找到或加载主类openWordDocument

最佳答案

这是我的错误,我在类路径中添加了 .dll 文件,因此无法编译 java 文件。之后我删除了该 dll 文件,jvm 开始编译并能够对类文件进行细化。

关于java - 错误: Could not find or load main class openWordDocument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com