NullPointerException on JXL Importsheet

I tried to use JAVA EXCEL API 2_6_12, and working with the importSheet function, but never success. Is there anything wrong with my code?



	public void write() throws IOException, WriteException {

		int i;
		File infile = new File(inputFile);
		File outfile = new File(outputFile);

		try {
		Workbook  sourceworkbook = Workbook.getWorkbook(infile);

		WritableWorkbook workbook =  Workbook.createWorkbook(outfile);

		Sheet sh =  sourceworkbook.getSheet(0);

		WritableSheet wSheet = workbook.importSheet("Report1", 0, sh);

			
		sourceworkbook.close();
		workbook.write();
		workbook.close();


		} catch (Exception e) {
			e.printStackTrace();
		} 

	}

Open in new window


inputFile, outputFile are string that contains the file name.  I tried to get value of cell from Sheet sh. So I sure the getSheet is working.
But the importSheet function always return following runtime error

 Exception in thread "main" java.lang.NullPointerException  
    at jxl.write.biff.SheetCopier.deepCopyCells(SheetCopier.java:996)  
    at jxl.write.biff.SheetCopier.importSheet(SheetCopier.java:542)  
    at jxl.write.biff.WritableSheetImpl.importSheet(WritableSheetImpl.java:2699)  
    at jxl.write.biff.WritableWorkbookImpl.importSheet(WritableWorkbookImpl.java:1897)  
mishelperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
code looks ok, have you tried with a different input file?
0
mishelperAuthor Commented:
yes I did and getting same error
0
CEHJCommented:
mishelper, can you make sure you've posted the full stack  trace?
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

CEHJCommented:
If this is the correct source at the link below, then there's a bug at line 996. See code  window below:

 http://www.docjar.org/html/api/jxl/write/biff/SheetCopier.java.html
//if (c.getCellFeatures() != null & c.getCellFeatures().hasDataValidation()); Produces NPE if getCellFeatures returns null

if (c.getCellFeatures() != null && c.getCellFeatures().hasDataValidation()); // << CORRECT

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mishelperAuthor Commented:
Exception in thread "main" java.lang.NullPointerException  
    at jxl.write.biff.SheetCopier.deepCopyCells(SheetCopier.java:996)  
    at jxl.write.biff.SheetCopier.importSheet(SheetCopier.java:542)  
    at jxl.write.biff.WritableSheetImpl.importSheet(WritableSheetImpl.java:2699)  
    at jxl.write.biff.WritableWorkbookImpl.importSheet(WritableWorkbookImpl.java:1897)
    at genExcel.WriteExcel.write(WriteExcel.java:58)
    at genExcel.WriteExcel.main(WriteExcel.java:155)

There are 2 more lines but I dont think it related, thanks
0
CEHJCommented:
OK. See my last comment
0
objectsCommented:
you don't have any charts on the sheet do you?
Have see issues with that library dealing with charts in the past
Unfortunatley support for that api has been falling, and the various problems that it has are not getting addressed.
Might be worth looking at alternate library that is more active.

One thing to try would be on an older version excel file
0
mishelperAuthor Commented:
objects- no I dont have the charts, actually I found that the function work with blank sheet. Even I create a sheet and add few characters in first cell then it not works.

CEHJ - so that mean I need to complie again myself or find another library right?




any other library that work with Excel you guys would suggest? thanks
0
CEHJCommented:
My guess is that you're NOT using the  version you think you are: the 2_6_12 version has had that bug fixed.
0
objectsCommented:
> actually I found that the function work with blank sheet.

yes expected it would, not a lot of use though

have a browse thru here
http://rgagnon.com/javadetails/java-0516.html
we mostly use POI
0
mishelperAuthor Commented:
CEHJ - I am using 2_6_12 but I found the bug you mentioned in the source code too.

objects - thanks, let me have a try with POI


thanks again for both your help!
0
CEHJCommented:
>>CEHJ - I am using 2_6_12 but I found the bug you mentioned in the source code too.

Download it again - it's not there now
0
mishelperAuthor Commented:

>>Download it again - it's not there now

http://www.andykhan.com/jexcelapi/jexcelapi_2_6_12.tar.gz

I just tried but found the source code still have it at line 996? And I did run it again and not working too, thanks
0
CEHJCommented:
Err, yes but that's not the correct site is it? ;) Don't use that: there could be other bugs too


http://downloads.sourceforge.net/project/jexcelapi/jexcelapi/2.6.12/jexcelapi_2_6_12.zip
0
mishelperAuthor Commented:
thanks again CEHJ,

but the link you gave me still have bug?

the source code in src\jxl\write\biff, line 996 of SheetCopier.java




anyway the link I provided is the website of JXL author.
0
CEHJCommented:
Sorry - my bad. I was looking at line 949 (where the bug is absent)
0
CEHJCommented:
Maybe you could be kind enough to report it if you're using his api ...
0
mishelperAuthor Commented:
Yes will do so, and thanks again for your kindly help!
0
CEHJCommented:
No problem ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.