Getting "NoClassDefFoundError" while reading the xlsx file | Selenium Forum
M
Posted on 23/03/2016
Hi,

I am trying to read an xlsx file from local drive, by using class Xls_Reader program created by Ashish with POI API. My code is this

public class Webuy {



@Test
public void testProductPurchaseProcess() throws FileNotFoundException
{

Xls_Reader xls = new Xls_Reader("D:\\Webuy.xlsx");
}

}

But When Trying to do the dry run I am facing the below issue.

FAILED: testProductPurchaseProcess
java.lang.NoClassDefFoundError: org/openxmlformats/schemas/drawingml/x2006/main/ThemeDocument
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:59)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:207)
at Xls_Reader.<init>(Xls_Reader.java:

[b:3n6yqp26]Options Tried[/b:3n6yqp26]

1. Running through Debug mode its says TestNG file not available. Add that through external path.
2. Deleted all POI jars and added fresh one.
3. Checked in stackoverflow but no use.

Can you please help me to resolve this.

M
Replied on 23/03/2016

it is working for me

Responsive image

M
Replied on 23/03/2016

[quote="qtpselenium.supp0rt@gmail.com":c593mc53]it is working for me[/quote:c593mc53]


Apologies I have attached wrong java file. Attaching the correct one now


M
Replied on 24/03/2016

can u cheeck with the latest attachment "Webuy". I am still facing the issue.

Your help is much appreciated


M
Replied on 24/03/2016

give me xlsx also.


M
Replied on 25/03/2016

Here is the xlsx file attached


M
Replied on 25/03/2016

working fine

Responsive image

M
Replied on 27/03/2016

I am not sure what is wrong with my files. The same file is throwing "NoClassDefFound" error.

Even I tried getting all the jars using MAVEN now as per the module20 tutorial. But still I see the same error.
Here is my code. I am attaching the same for reference.

package com.qtpselenium.learn.testNG.suiteA;

import org.testng.annotations.Test;

import com.qtpselenium.learn.testNG.util.Utility;
import com.qtpselenium.learn.testNG.util.Xls_Reader;

public class Test1 {

@Test
public void test1(){

Xls_Reader xls = new Xls_Reader("C:\\Rediff_Framework\\Suite.xlsx");
Utility.isSuiteRunnable("SuiteA", xls);

}

}


*************Utility code*********************
package com.qtpselenium.learn.testNG.util;

public class Utility {

//test suite is runnable or not
public static boolean isSuiteRunnable(String suiteName, Xls_Reader xls){

int rows = xls.getRowCount("Suite");

for(int rNum=2;rNum<=rows;rNum++){
String data = xls.getCellData("Suite", "SuiteName", rNum);
System.out.println(data);
}
return false;
}
}

***************Console Error*****************
[TestNG] Running:
C:\Users\pavanu\AppData\Local\Temp\testng-eclipse-1649974894\testng-customsuite.xml

FAILED: test1
java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.apache.xerces.parsers.AbstractDOMParser.startDocument(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at org.apache.poi.util.DocumentHelper.readDocument(DocumentHelper.java:96)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.parseContentTypesFile(ContentTypeManager.java:377)
at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.<init>(ContentTypeManager.java:103)
at org.apache.poi.openxml4j.opc.internal.ZipContentTypeManager.<init>(ZipContentTypeManager.java:54)
at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:186)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:696)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:280)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:274)
at com.qtpselenium.learn.testNG.util.Xls_Reader.<init>(Xls_Reader.java:33)
at com.qtpselenium.learn.testNG.suiteA.Test1.test1(Test1.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:702)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:768)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1188)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1113)
at org.testng.TestNG.run(TestNG.java:1025)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:207)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:178)
Caused by: java.lang.ClassNotFoundException: org.w3c.dom.ElementTraversal
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 57 more


===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.XMLReporter@d8a125: 17 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@1c0ae76: 22 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@1b81d4f: 8 ms
[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 4 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter@3a9c52: 6 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@ad9f5d: 31 ms


M
Replied on 27/03/2016

add this in pom

[quote:j8ewar9a]<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>[/quote:j8ewar9a]


M
Replied on 28/03/2016

tried with updated POM, but still facing this issue...

firstly I am not able to understand wht is this error.. can i get detail explanation pls.

[attachment=0:qcf180re]error.jpg[/attachment:qcf180re]

Responsive image

M
Replied on 28/03/2016

[quote:1bavh5gc]java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
[/quote:1bavh5gc]

this error comes because of the bug in the jar files. we need to change the version to get it to work.


M
Replied on 29/03/2016

Apologies, but I am not able to understand this.

Yesterday I have added the suggested dependency to the POM

<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>

this is executing with testNG. But the issue is the program is not moving to for loop in isSuiteRunnable function @ Utility class. Also I tried with couple of Println statements before the loop. Even they are not executed. Simply the boolean return is picked up from the function due to the last statement.

Please help me to understand this.

Responsive image

M
Replied on 29/03/2016

what is the problem you're having? explain it to me again.


M
Replied on 29/03/2016

I am able to execute Test1.java file and it is calling "isSuiteRunnable" function successfully. But the for loop in "isSuiteRunnable" function is not executing and I dont see the output for this loop

for(int rNum=2;rNum<=rows;rNum++)
{
String data = xls.getCellData("Suite", "SuiteName", rNum);
System.out.println("this is the data"+data);
if(data.equals(suiteName)){
String runmode = xls.getCellData("Suite", "Runmode", rNum);
if(runmode.equals("Y"))
return true;
else
return false;
}

while debugging this I can see "No class found error" in debug mode. That is the screen shot I have shared in the morning.

When you see the console output carefully My expectation is that it should print all the details from Suite sheet. but is not printing any data just a return value from the function. Hope this is detail.

**************************************************************************
[TestNG] Running:
C:\Users\pavanu\AppData\Local\Temp\testng-eclipse--1146255929\testng-customsuite.xml

0
false
PASSED: test1

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.XMLReporter@1f4af32: 9 ms
[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 0 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@47c130: 31 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@178743b: 15 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@18aeabe: 2 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter@1cc1f09: 3 ms


M
Replied on 29/03/2016

could you send me the entire project with xlsx file.


M
Replied on 29/03/2016

Here the complete project and xlsx file....

I am trying to simulate the same wht you have taught in Module20
I am not able to understand why the code in the "isSuiteRunnable" function is not working. Please help


M
Replied on 30/03/2016

where is testng.xml file located.


M
Replied on 30/03/2016

we don't need testng.xml. I am just calling Utility class in Test1 class, where in utility class is calling data from Xls_reader.

Just it is not executing for loop.

its been so long but I am not able to trace it. Can we Please have f2f call to close this issue.

your support is much appreciated. Thanks


M
Replied on 30/03/2016

sheet name was wrong

Responsive image

M
Replied on 30/03/2016

Woow.. my bad. I am not able to get this.
Its working now.
Apologies for the careless mistake. Have learned from this. Thanks.