使用jacob 抛出的异常,哪位大侠遇到过?

coff_cola 2009-08-19 11:44:03
java.lang.NoClassDefFoundError: Could not initialize class com.jacob.activeX.ActiveXComponent
at com.word.util.Document.<init>(Document.java:28)
at com.word.util.WordBean.newDoce(WordBean.java:10)
at com.word.action.WordAction.savewords(WordAction.java:56)
at com.word.action.WordAction.saveword(WordAction.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
...全文
2362 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
coff_cola 2009-08-23
  • 打赏
  • 举报
回复
我现在刚开始学jacob,有些方法只是知道大概做什么用的,并不知道确切是怎么实现的,所以现在遇到问题很难搞定,虽然也有调试,但是调试没有发现问题,实际是不知道从哪里去分析程序出错的原因,就像楼上说的出错的原因是映射的问题,但是是什么映射?怎么映射的?现在项目很赶,但是我现在卡在这地方了,很郁闷~~
tidelgl 2009-08-23
  • 打赏
  • 举报
回复
com.jacob.com.ComFailException: Can't map name to dispid: SaveAs

居然是映射的问题,楼主怎么找不出的,楼主应该多加调试,调试可以解决大部分问题.
coff_cola 2009-08-22
  • 打赏
  • 举报
回复
谢谢楼上的哈,我改了一下程序,换了一下jacob的jar为1.15版本(jdk 1.5,tomcat 6.0),卸掉office2007只用2003,现在上面的问题排除了,但是又出现了新的问题,我认真的检查了一下程序确实麽看出来哪里错,我把源码贴出来请大家帮我看看,谢谢先!

public class WordAction extends DispatchAction
{
// 请求入口

public ActionForward saveword(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception
{
String filemodule="D:/bb.doc";
PrivilegeUser pr=new PrivilegeUser();
pr.setName(request.getParameter("name"));
pr.setSex(request.getParameter("sex"));
this.savewords(filemodule,pr.getName(),pr);
request.setAttribute("pr", pr);
return mapping.findForward("showxx");
}
public void savewords(String filemodule,String username,PrivilegeUser pu)
{
try
{
System.out.println("-------------");
WordBean wb=new WordBean();
wb.newDoce(filemodule, "d:/", username);//根据用户名创建一个word文件
String infile="d:/"+username+"个人资料.doc";
wb.replaceWord(infile,pu);//根据
}
catch (Exception e)
{
e.printStackTrace();
}
}
}



public class WordBean // extends Panel
{
Document docc =null;
public void newDoce(String modulefile, String newfilepath, String username) {
try {
docc = new Document();
docc.newDoc(modulefile, newfilepath + username + "个人资料.doc");
docc.close(true);
} catch (Exception e)
{
e.printStackTrace();
}
}
public void replaceWord(String inFile, PrivilegeUser pu) {
try {
boolean flag = true;
String[] module = { "name", "sex" };
String[] pulist = { pu.getName(), pu.getSex(), pu.getPhoto() };
for (int i = 0; i < module.length; i++) {
if (flag) {
docc = new Document();
docc.open(inFile);
if (module[i].equals("pic")) {
File file = new File(pulist[i]);
flag = docc.insertimageAtBookmark(module[i], file);
} else
flag = docc.insertAtBookmark(module[i], pulist[i]);
docc.close(true);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

主要的处理方法

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

// Referenced classes of package com.heavenlake.wordapi:
// StyleWarning, TableStyleWarning

public class Document
{

private Dispatch doc;

private Dispatch documents;

// 选定的范围或插入点
private Dispatch selection;

private static String newFileName;

private ActiveXComponent word;

public Document()
{

word = new ActiveXComponent("Word.Application");
// word.setProperty("Visible", new Variant(false)); //不可见打开word
documents = word.getProperty("Documents").toDispatch();
// doc=Dispatch.call(documents, "Add").toDispatch();// create
}

private void close(Dispatch doc, boolean saveOnExit)
{
if (doc != null)
{
Dispatch.call(doc, "Close", new Variant(saveOnExit));
word.invoke("Quit", new Variant[0]);
ComThread.Release();
}
}

public void close(boolean saveOnExit) throws Exception
{
if (newFileName!=null&&newFileName.length() > 0)
{
if (saveOnExit)
{
saveAs(newFileName);
close(doc, false);
}
}
else
{
close(doc, saveOnExit);
}
}

private boolean find(Dispatch selection, String toFindText)
{
ActiveXComponent _tmp = word;
if (toFindText == null || toFindText.equals("")){

return false;

}
Dispatch find = ActiveXComponent.call(selection, "Find").toDispatch();
Dispatch.put(find, "Text", toFindText);
Dispatch.put(find, "Forward", "True");
Dispatch.put(find, "Format", "True");
Dispatch.put(find, "MatchCase", "True");
Dispatch.put(find, "MatchWholeWord", "False");
return Dispatch.call(find, "Execute").getBoolean();
}

public boolean find(String toFindText)
{
boolean flag = find(selection, toFindText);
return flag;
}

public void insert(File imageFile)
{
if (imageFile.exists())
{
replaceImage(selection, imageFile.getAbsolutePath());
}
}

public void insertAtBookmark(String bookmarkName, File imageFile)
{
if (imageFile.exists())
{
Dispatch bookmarkRange = getBookmark(bookmarkName);
replaceImage(bookmarkRange, imageFile.getAbsolutePath());
insertBookmark(bookmarkRange, bookmarkName);
}
else
{
System.out.println("图片文件不存在");
}
}
public void insertln()
{
Dispatch range = Dispatch.get(selection, "Range").toDispatch();
Dispatch.call(range, "InsertParagraphAfter");
moveDown(1);
}

public void newDoc(String template, String fileName)
{
File file = new File(template);
if (file.exists())
{
doc = Dispatch.call(documents, "Open", template).toDispatch();
newFileName = fileName;//命名文件,但没把文件保存.
}
else
{
System.out.println("模板文件不存在");
}
}

public void newDoc(String fileName) throws Exception
{
doc = Dispatch.call(documents, "Open").toDispatch();
selection = Dispatch.get(word, "Selection").toDispatch();
newFileName = fileName;
}

public void open(String fileName)
{
File file = new File(fileName);
if (file.exists())
{
doc = Dispatch.call(documents, "Open", fileName).toDispatch();
selection = Dispatch.get(word, "Selection").toDispatch();
}
else
{
System.out.println("文件不存在,不能打开");
}
}

public List readTable(int tbIndex, int fromRow) throws Exception
{
ArrayList tableData = new ArrayList();
if (fromRow < 1)
{
fromRow = 1;
}
if (tbIndex < 1)
{
tbIndex = 1;
}
Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
int tablesCount = Dispatch.get(tables, "Count").getInt();
if (tablesCount < tbIndex)
{
throw new Exception(
"\u6307\u5B9A\u7684\u8868\u683C\u4E0D\u5B58\u5728\u3002\u6253\u5F00\u7684\u6587\u6863"
+ "\u4E2D\u6CA1\u6709\u8868\u683C\u3002");
}
if (tablesCount < tbIndex)
{
throw new Exception(
"\u6307\u5B9A\u7684\u8868\u683C\u4E0D\u5B58\u5728\u3002\u6253\u5F00\u7684\u6587\u6863"
+ "\u4E2D\u53EA\u6709" + tablesCount + "\u5F20\u8868\u3002");
}
Dispatch table = Dispatch.call(tables, "Item", new Variant(tbIndex)).toDispatch();
Dispatch rows = Dispatch.get(table, "Rows").toDispatch();
int rowsCount = Dispatch.get(rows, "Count").getInt();
Dispatch Columns = Dispatch.get(table, "Columns").toDispatch();
int Columnscount = Dispatch.get(Columns, "Count").toInt();
for (int i = fromRow; i < rowsCount + 1; i++)
{
ArrayList rowData = new ArrayList();
for (int j = 1; j < Columnscount + 1; j++)
{
Dispatch cell = Dispatch.call(table, "Cell", i + "", j + "").toDispatch();
Dispatch Range = Dispatch.get(cell, "Range").toDispatch();
String text = Dispatch.get(Range, "Text").toString();
rowData.add(text.substring(0, text.length() - 1));
}
tableData.add(rowData);
}
return tableData;
}

public boolean insertAtBookmark(String bookmarkName, String newText)
{
boolean flag = insertAtBookmark(bookmarkName, newText, null);

return flag;
}

public boolean insertAtBookmark(String bookmarkName, String newText, String styleName)
{
try
{
Dispatch bookmarkRange;
bookmarkRange = getBookmark(bookmarkName);
replace(newText);
insertBookmark(bookmarkRange, bookmarkName);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
private Dispatch getBookmark(String bookmarkName)
{
//获取bookmarkName的标签
Dispatch bookmark = Dispatch.call(doc, "Bookmarks", bookmarkName).toDispatch();
bookmark = Dispatch.get(bookmark, "Range").toDispatch();//在全局的范围内获取
return bookmark;
}
private void replace( String newText)
{
Dispatch.put(selection, "Text", newText);
}

private void insertBookmark(Dispatch selection, String bookmarkName)
{//往dispatch对象添加一个书签对象.
Dispatch Bookmarks = Dispatch.get(doc, "Bookmarks").toDispatch();
Dispatch.call(Bookmarks, "Add", bookmarkName, selection);
}

public boolean replace(String toFindText, String newText)
{
if (!find(toFindText))

return false;

boolean leaf = false;
boolean flag = find(toFindText);
if (flag)
{
replace( newText);
leaf = true;
}
return leaf;
}

/**
* 全局替换文本
*
* @param toFindText
* 查找字符串
* @param newText
* 要替换的内容
*/


private void replaceAll(Dispatch selection, String oldText, String newText)
{
moveStart(selection);
for (; find(selection, oldText); Dispatch.call(selection, "MoveRight"))
{
replace( newText);
}
}

public void replaceAll(String oldText, String newText)
{
replaceAll(selection, oldText, newText);
}
public void saveAs(String outputFile)
{
Dispatch.call(doc, "SaveAs", outputFile);

}

public boolean insertimageAtBookmark(String bookmarkName, File imageFile) throws Exception
{
//插入图片
if (imageFile.exists())
{
Dispatch bookmarkRange = getBookmark(bookmarkName);//获取指定的标签对象
replaceImage(bookmarkRange, imageFile.getAbsolutePath());
insertBookmark(bookmarkRange, bookmarkName);
return true;
}else
{
return false;
}
}
private void replaceImage(Dispatch selection, String imagePath)
{//入word里边添加图片s
Dispatch.call(Dispatch.get(selection, "InLineShapes").toDispatch(), "AddPicture", imagePath);
}


}



问题就出在这个方法:
public void saveAs(String outputFile)
{
Dispatch.call(doc, "SaveAs", outputFile);

}
异常信息:
com.jacob.com.ComFailException: Can't map name to dispid: SaveAs
tidelgl 2009-08-22
  • 打赏
  • 举报
回复
tidelgl 2009-08-22
  • 打赏
  • 举报
回复
楼主,变量定义时没有对吧...
该初始化的就是初始化
coff_cola 2009-08-21
  • 打赏
  • 举报
回复
换了jdk版本之后这个问题解决了,可是又出了另外一个问题

com.jacob.com.ComFailException: Invoke of: Add
Source: Microsoft Word
Description: Word

at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invokev(Dispatch.java:804)
at com.jacob.com.Dispatch.callN(Dispatch.java:440)
at com.jacob.com.Dispatch.call(Dispatch.java:520)
at com.word.util.Document.newDoc(Document.java:176)
at com.word.util.WordBean.newDoce(WordBean.java:11)
at com.word.action.WordAction.savewords(WordAction.java:56)
at com.word.action.WordAction.saveword(WordAction.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
java.lang.NullPointerException

coff_cola 2009-08-20
  • 打赏
  • 举报
回复
有可能,我jdk 用的1.6的,我改了试试先,谢谢楼上的!
jinchun1234 2009-08-20
  • 打赏
  • 举报
回复
估计是包的版本不对应
源码链接: https://pan.quark.cn/s/0f7c75cb3aad ### MIPI Video Mode 与 Command Mode 的差异 #### 一、引言 MIPI (Mobile Industry Processor Interface) 是一种用于连接移动设备中处理器及其外围设备的标准化接口。MIPI 接口支持多种协议,其中包含 DSI (Display Serial Interface) 和 DCS (Display Control Interface) 等协议。在 MIPI 接口的应用中,主要涉及两种工作模式:Video Mode(视频模式)和 Command Mode(命令模式)。本文旨在系统性地阐述这两种模式的工作机制、特性以及实际应用环境。 #### 二、LCD RAM 概念说明 在进一步探讨 MIPI 的两种模式之前,有必要对文中提及的“LCD RAM”概念进行明确。实际上,“LCD RAM”并非一个通用术语,而是本文作者用来描述 LCD 控制器中用于存储显示数据的内存区域。LCD(Liquid Crystal Display,液晶显示屏)通常配备一个控制 IC(Integrated Circuit,集成电路),该控制 IC 可能内置 RAM 以缓存显示数据。 #### 三、MIPI Video Mode(视频模式) **定义:** - 视频模式是一种类似于传统 RGB 接口的工作模式,它要求主机持续不断地向显示器传输刷新数据。 - 在这种模式下,数据和控制信号以报文的形式通过 MIPI 总线进行传输。 - 显示器本身无需配备帧缓冲器,因为主机会周期性地刷新屏幕。 **特点:** 1. **实时性高:** 主机需要不...
源码下载地址: https://pan.quark.cn/s/a4b39357ea24 在电磁模拟技术中,CST(Computer Simulation Technology)是一种被广泛采纳的软件工具,它主要用于电磁场、微波、天线以及射频系统的设计工作。本资料将详细分析CST软件中离散端口的具体配置方法,这些方法对于提升仿真结果的精确度和专业水准具有决定性作用。离散端口在CST软件中扮演着模拟信号输入或输出的重要角色,它们构成了仿真模型不可或缺的部分。在配置离散端口时,一个核心的原则是保证端口的方向与网格线保持一致,这是因为这样做能够有效降低计算过程中产生的误差,并确保仿真数据的有效性。如果未能遵循这一指导原则,可能会引发未知的计算问题,进而导致仿真结果失去可靠性。 在CST软件中配置离散端口,通常需要借助“Pick Points”这一功能。通过选择“Pick Edge Center”选项,端口将被设定在模型边缘的中心位置上。然而,这种做法并不总是能够确保端口与网格线保持平行。在某些特定情形下,模型的几何构造可能不允许直接选取一个与网格线平行的边作为端口的安装位置。 为了克服这一挑战,可以采用多种不同的策略。如果模型本身已经包含一条与馈电口平行的边,那么可以直接利用这条边来建立端口,此时CST软件会自动调整端口使其与网格线对齐。另一种可选的方法是,当模型不具备现成的平行边时,用户可以手动构建一个几何结构,比如一个立方体,并使其边缘与馈电口平行。通过这种方式,新建立的几何结构的边缘就可以作为端口的位置,从而确保端口与网格线的平行关系。 在实施上述操作时,必须关注端口尺寸的合理性和物理意义的一致性。端口的尺寸应当依据实际天线馈电部分的尺寸进行适当调整,过大的端口或...
代码下载链接: https://pan.quark.cn/s/a4b39357ea24 【使用TensorFlow进行图像识别】 图像识别作为计算机视觉领域的关键任务之一,其核心在于通过算法解析和理解图像所包含的信息。在此资源中,我们将集中探讨如何借助功能强大的深度学习框架TensorFlow来执行手写数字识别。手写数字识别构成了众多实际应用的基础,例如自动支票处理、光学字符识别(OCR)等场景。 TensorFlow是由Google创建的一个开源库,它主要用于数值运算和机器学习,尤其在深度学习方面表现卓越。其核心优势在于可以构建并训练复杂的神经网络架构,并且在多种硬件环境中实现高效执行,涵盖CPU和GPU平台。 在此实践项目中,我们将运用TensorFlow来构建一个卷积神经网络(CNN)模型,这种架构是处理图像数据的理想选择。CNNs通过模仿人脑视觉皮层的运作机制,能够自主地提取图像中的关键特征,进而达成识别目标。在手写数字识别的特定情境下,这些特征可能涉及笔画的几何形态、走向以及相互间的连接模式。 对于CNN的基础结构,我们需要具备相应的认知,其通常由卷积层、池化层、全连接层以及激活函数等部分组成。卷积层借助滤波器(亦称卷积核)对图像进行扫描,以捕捉局部特征;池化层则用于降低数据维度,同时保留核心信息;全连接层将特征向量映射至各类别的概率分布;而激活函数如ReLU则通过引入非线性元素,使模型能够学习更为复杂的模式。 在此案例中,建议采用MNIST数据集,这是一个广泛用于手写数字识别的标准测试集。该数据集包含60,000个训练样本和10,000个测试样本,每个样本均为28x28像素的灰度图像,代表0到9这十个数字中的某一个。为了训练模型,必须首先加载数据,并...

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧