1. Problem phenomenon
In the process of exporting to Excel, the program reports the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream
at PIOTest.main(PIOTest.java:31)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
Two, the cause of the problem
It can be seen from the error message that this exception usually occurs when you use the org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream class in your code, but the dependency package commons-io where this class is located has not been introduced or does not exist.
3. Solutions
To solve this problem, you need to introduce the commons-io package into the project.
If you use Maven to manage dependencies, you can add the following dependencies to the pom.xml file:
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
Note: Version 2.11.0 and above must be used here , otherwise NoClassDefFoundError will still be reported .
Maven remote warehouse address: https://mvnrepository.com/artifact/commons-io/commons-io
PS
If you don't use Maven, you can manually download the commons-io jar package and add it to the project's lib directory or classpath.
If the commons-io package has been introduced into the project, but ClassNotFoundException still occurs, it may be because the compilation environment and the running environment are inconsistent, and you need to check whether the compilation and running environments are consistent.