2012-07-20 112 views
0

荫尝试使用侨光打开Microsoft Word文档主类,错误:无法找到或加载openWordDocument

吹是代码:

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

} 

当上面的代码得到错误的IAM运行Error: Could not find or load main class openWordDocument

请帮助如何解决上述问题。

+0

您需要告诉我们您是如何编译它以及如何尝试运行它的。 – 2012-07-20 15:51:45

+0

@JonSkeet哦乔恩正在看这个.Iam试图通过运行java应用程序在Eclispse中运行它。我错了吗? – developer 2012-07-20 16:25:08

回答

1

它是我的错误,我在类路径中添加了.dll文件,所以iam无法编译java文件,之后我删除了该dll文件,jvm开始编译并能够处理类文件。

0

警告!

检查您的已将外部库(如.jar文件)路径添加到您的项目中。 路径应该有规则的格式。例如它应该没有像“+”,...或空格那样的特殊字符。

我以前在Eclipse IDE中遇到过这个严重的问题,请更改我的项目库的路径目录,然后再一切正常。

+0

这个问题已经有了一个自我接受的答案。 – 2012-09-28 12:41:40

相关问题