-3

I am having this problem with reading a .doc or .docx file in Java:

java.lang.NoClassDefFoundError: org/apache/poi/hwpf/HWPFDocument

I don't understand why this is happening and would appreciate any help getting rid of this error.

eboix
  • 5,113
  • 1
  • 27
  • 38

1 Answers1

2

Well, that sounds like you haven't put the relevant Apache POI jar file(s) into the classpath you're using at execution time. Without more information, that's about all we can say.

  • Find out which jar files are required
  • Find out what's controlling your classpath (which will depend on what kind of app you're running)
  • Make sure all the jar files are in place
  • Rerun
  • Profit :)

For example, from the command line, on Windows, you might want to run:

java -cp .;poi-whatever.jar foo.bar.Test

(Replace the jar file name and your entry point name appropriately.)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • I'm run demo the programs read file .doc and .docx how to set classpath??? – user1683695 Sep 19 '12 at 17:05
  • `java.lang.NoClassDefFoundError: org/apache/poi/hwpf/HWPFDocument at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2442) at java.lang.Class.getMethod0(Class.java:2685) at java.lang.Class.getMethod(Class.java:1620) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:484) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:476) Caused by: java.lang.ClassNotFoundException: org.apache.poi.hwpf.HWPFDocument` – user1683695 Sep 19 '12 at 17:13
  • 1
    You haven't told us anything about how you're trying to run the code. – Jon Skeet Sep 19 '12 at 17:24
  • I added the library of Apache POI 3.8 in the project.now,what must I do next? – user1683695 Sep 19 '12 at 17:36
  • :that [link](http://nq8.upanh.com/b1.s30.d1/0bba3001d6a1504cfae22ad4a7c89c28_49271818.help2.png) – user1683695 Sep 19 '12 at 17:46
  • that class isn't available on my system.what must I do??? – user1683695 Sep 19 '12 at 17:47