Comment éviter de java.lang.NoClassDefFoundError

J'ai un code pour l'ajout de textes existants .fichier doc, et il va enregistrer sous un nom différent à l'aide de apache POI.

Voici le code que j'ai essayé jusqu'à présent

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFFooter;
import org.apache.poi.xwpf.usermodel.XWPFTable;
public class FooterTableWriting {
public static void main(String args[])
{
String path="D:\\vignesh\\AgileDocTemplate.doc";
String attch="D:\\Attach.doc";
String comment="good";
String stat="ready";
String coaddr="xyz";
String cmail="[email protected]";
String sub="comp";
String title="Globematics";
String cat="General";
setFooter(path, attch, comment, stat, coaddr, cmail, sub, title, cat);
}
private static  void setFooter(String docTemplatePath,String attachmentPath,String comments,String status,String coAddress,String coEmail,String subject,String title,String catagory)
{
try{
InputStream input = new FileInputStream(new File(docTemplatePath));
XWPFDocument document=new XWPFDocument(input);
XWPFHeaderFooterPolicy headerPolicy =new XWPFHeaderFooterPolicy(document);
XWPFFooter footer = headerPolicy.getDefaultFooter();
XWPFTable[] table = footer.getTables();
for (XWPFTable xwpfTable : table)
{
xwpfTable.getRow(1).getCell(0).setText(comments);
xwpfTable.getRow(1).getCell(1).setText(status);
xwpfTable.getRow(1).getCell(2).setText(coAddress);
xwpfTable.getRow(1).getCell(3).setText(coEmail);
xwpfTable.getRow(1).getCell(4).setText(subject);
xwpfTable.getRow(1).getCell(5).setText(title);
xwpfTable.getRow(1).getCell(6).setText(catagory);
}
File f=new File (attachmentPath.substring(0,attachmentPath.lastIndexOf('\\')));
if(!f.exists())
f.mkdirs();
FileOutputStream out = new FileOutputStream(new File(attachmentPath));
document.write(out);
out.close();
System.out.println("Attachment Created!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

La suivante est ce que j'ai

    org.apache.poi.POIXMLException: org.apache.xmlbeans.XmlException: error: The document is not a document@http://schemas.openxmlformats.org/wordprocessingml/2006/main: document element mismatch got themeManager@http://schemas.openxmlformats.org/drawingml/2006/main
at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:124)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:200)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:74)
at ext.gt.checkOut.FooterTableWriting.setFooter(FooterTableWriting.java:32)
at ext.gt.checkOut.FooterTableWriting.main(FooterTableWriting.java:25)
Caused by: org.apache.xmlbeans.XmlException: error: The document is not a document@http://schemas.openxmlformats.org/wordprocessingml/2006/main: document element mismatch got themeManager@http://schemas.openxmlformats.org/drawingml/2006/main
at org.apache.xmlbeans.impl.store.Locale.verifyDocumentType(Locale.java:458)
at org.apache.xmlbeans.impl.store.Locale.autoTypeDocument(Locale.java:363)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1279)
at org.apache.xmlbeans.impl.store.Locale.parseToXmlObject(Locale.java:1263)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:345)
at org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument$Factory.parse(Unknown Source)
at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:92)
... 4 more

J'ai ajouté tous les fichiers jar correspondant à cela, mais encore je ne trouve pas la solution.Je suis nouveau sur ce apache poi, donc merci de m'aider avec des explications et des exemples.
Grâce

On dirait que vous devez poi-ooxml-schemas.jar qui vient dans le Apache POI de distribution. Juste l'ajout d'un seul bocal ne signifie pas que vous avez toutes les classes du framework.
Êtes-vous à l'aide d'Eclipse?
oui....Je suis à l'aide d'eclipse
Comment l'éviter? Comme d'habitude, assurez-vous, toutes les classes sont sur le chemin de la classe 😉
lol @EJP si vous avez réellement lire les commentaires de l'op dit qu'il se fixe, la première chose que par l'ajout d'un supplément pot et maintenant il commence à se faire une autre erreur. Puis il a dit qu'il avait mise à l'erreur. Je souhaite que je pourrais downvote votre commentaire.

OriginalL'auteur Vignesh Vino | 2013-02-27