Skip to main content
Ben Nadel at CFCamp 2023 (Freising, Germany) with: Denis Burimov
Ben Nadel at CFCamp 2023 (Freising, Germany) with: Denis Burimov ( @Denis_Burimov )

POIUtility - Object Instantiation Exception

By on
Tags:

Every now and then, I get people contacting me about problems using my POIUtility.cfc. They are usually getting this error:

Object Instantiation Exception. An exception occurred when instantiating a java object.

While I think there might be several reasons that this object instantiation could occur, usually, with the POI Utility ColdFusion component, I find that it is due to the file path that's being used. The POI Utility requires a full file path. This means that you should be using something like ExpandPath( FILE ) when defining your file path. Running this code:

<cfset objSheet = objPOIUtility.ReadExcel(
	FilePath = "meals.xls"
	) />

... will throw that object instantiation error since "meals.xls" is not a full path. However, running this code, with the full path, will not throw any error and will work just fine:

<cfset objSheet = objPOIUtility.ReadExcel(
	FilePath = ExpandPath( "meals.xls" )
	) />

Hope that helps with people having this problem.

Want to use code from this post? Check out the license.

Reader Comments

218 Comments

Heh, every time my project manager has an old copy of a site moved or cloned and doesn't remember to open up the settings file and re-adjusts paths, I get a "Hey... can you look into this Object Instantiation Error?" I send an email back saying, "Hey, did you fix the temp/library paths?"

218 Comments

...? When you're making the big bucks and you're at the top of the food chain like, Mr. Nadel, Chief Technology Officer, wouldn't you have managers?

46 Comments

Ive also received that error when i have the dang xls file open on my browser. This only occurs when i try to read in a file. Simple solution to that problem.

12 Comments

When I use this cfc and the ziputility cfc, I get the same errors around the area that the path is used to instantiate the file input stream:

<cfset LOCAL.FileInputStream = CreateObject(
"java",
"java.io.FileInputStream"
).Init(
LOCAL.FilePath
) />

I'm using a full path for both pieces of code:

d:\inetpub\directoryname\anotherdirectoryname\bobthefile.zip

Any clues?

Thanks and happy Friday!
Steph

15,640 Comments

@Stephanie,

If you do this:

#FileExists( "d:\inetpub\directoryname\anotherdirectoryname\bobthefile.zip" )#

... what does it give you?

12 Comments

It creates the zip drive but it's when it tries to add the files, it chokes. I imagine on filepath.

exact line of zipUtility is 282:

<cfset LOCAL.FileInputStream = CreateObject(
"java",
"java.io.FileInputStream"
).Init(
LOCAL.FilePath
) />

15,640 Comments

@Stephanie,

I am not sure what the problem is. Sorry I cannot be more help on this. It looks like you simply cannot create the file stream. The only reason I have come across on this is that the file doesn't exist or is an invalid path or something.

12 Comments

Here is the full error without the full paths for security reasons... The zip file gets created and is 1k but it barfs on adding files to the stream....

Any clues on even how to debug this myself would be great. I am not a java child. I know my CF ok but not java...

Thanks so much!
Steph

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.

The following information is meant for the website developer for debugging purposes.

Error Occurred While Processing Request
Object Instantiation Exception.
An exception occurred when instantiating a java object. The cause of this exception was that: .

The error occurred in ...cfc\ZipUtility.cfc: line 286
Called from ...OpptyImportBackend.cfm: line 186
Called from ...OpptyImportBackend.cfm: line 169
Called from ...OpptyImportBackend.cfm: line 1
Called from ...cfc\ZipUtility.cfc: line 286
Called from ...OpptyImportBackend.cfm: line 186
Called from ...OpptyImportBackend.cfm: line 169
Called from ...OpptyImportBackend.cfm: line 1

284 : "java.io.FileInputStream"
285 : ).Init(
286 : GetFileFromPath(LOCAL.FilePath)
287 : ) />
288 :

--------------------------------------------------------------------------------

Resources:
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.


Browser Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705; .NET CLR 2.0.50727; InfoPath.1)
Remote Address 91.103.41.50
Referrer https://.../OpptyImportWizardMapping.cfm
Date/Time 22-Oct-07 09:02 AM

Stack Trace (click to expand)
at cfZipUtility2ecfc1962888858$funcCOMPRESS.runFunction(...cfc\ZipUtility.cfc:286) at cfOpptyImportBackend2ecfm376580135._factor5(...OpptyImportBackend.cfm:186) at cfOpptyImportBackend2ecfm376580135._factor6(...OpptyImportBackend.cfm:169) at cfOpptyImportBackend2ecfm376580135.runPage(...OpptyImportBackend.cfm:1) at cfZipUtility2ecfc1962888858$funcCOMPRESS.runFunction(...cfc\ZipUtility.cfc:286) at cfOpptyImportBackend2ecfm376580135._factor5(...OpptyImportBackend.cfm:186) at cfOpptyImportBackend2ecfm376580135._factor6(...OpptyImportBackend.cfm:169) at cfOpptyImportBackend2ecfm376580135.runPage(...OpptyImportBackend.cfm:1)

java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedConstructorAccessor274.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:128)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:56)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:1634)
at cfZipUtility2ecfc1962888858$funcCOMPRESS.runFunction(...cfc\ZipUtility.cfc:286)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:344)
at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:290)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:254)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:56)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:207)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:169)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:194)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:146)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:1634)
at cfOpptyImportBackend2ecfm376580135._factor5(...OpptyImportBackend.cfm:186)
at cfOpptyImportBackend2ecfm376580135._factor6(...OpptyImportBackend.cfm:169)
at cfOpptyImportBackend2ecfm376580135.runPage(...OpptyImportBackend.cfm:1)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:349)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:225)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:69)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:52)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:115)
at coldfusion.CfmServlet.service(CfmServlet.java:107)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:78)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:257)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:541)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:204)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:318)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:426)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:264)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Caused by: java.io.FileNotFoundException: SOBAccreditations200710Mon.xls (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
... 43 more

15,640 Comments

Oooh, I see. Ok, that makes sense. Yeah, right now, you have to add one at a time. But, that is a cool idea to do a list.

1 Comments

Hi Ben,
on some Excel files i get the message Object Instantiation Exception. An exception occurred when instantiating a java object, too.
I tried with expandpath(), but with no success. Now i have downloaded the new version of jarkarta Poi, version 3 on http://apache.secsup.org/dist/jakarta/poi/release/bin/.
I deleted the old poi files files on the coldfusion lib directory, poi-2.5.1-final-20040804.jar, poi-contrib-2.5.1-final-20040804.jar and replaced them with the new version poi-3.0-rc4-20070503.jar and poi-contrib-3.0-rc4-20070503.jar. After restarting the coldfusion server, i can read my Excel files with POIUtility.cfc.

12 Comments

the error:

Object Instantiation Exception.
An exception occurred when instantiating a java object. The cause of this exception was that: .

The error occurred in ...\POIUtility.cfc: line 883

............

881 : "org.apache.poi.hssf.usermodel.HSSFWorkbook"
882 : ).Init(
883 : LOCAL.ExcelFileSystem
884 : );
885 :

15,640 Comments

@Stephanie,

The system should not matter, as far as I know. I am on a Windows system and it works fine. Can you post the few lines of code that actually creates the POIUtility? ... The CreateObject() lines.

15,640 Comments

@Felix,

Interesting. I wonder why it was working in some files and not for others. Maybe it was just a bug in the Java code, seeing as the new release fixed it. Thanks for sharing that the new version works.

12 Comments

<cfset objPOI = CreateObject("component", "POIUtility" ).Init() >

<cfset arrSheets = objPOI.ReadExcel( FilePath = tempFile , HasHeaderRow = true ) >

<cfoutput>#arrSheets.name#</cfoutput>

It crashes at cfset arrSheets with the error I posted.

12 Comments

All I need it for right now is to read in a sheet name.

I also tried the simple code below but it crashes at cfset wb with the same error. I am on a windows server 2003 enterprise edition...

Error:

Object Instantiation Exception.
An exception occurred when instantiating a java object. The cause of this exception was that: .

Code:

<cfset fileIn = createObject("java","java.io.FileInputStream").init("#tempFile#")/>

<cfset fs = createObject("java","org.apache.poi.poifs.filesystem.POIFSFileSystem").init(fileIn)/>

<cfset wb = createObject("java","org.apache.poi.hssf.usermodel.HSSFWorkbook").init(fs)/>
<cfset sheet = wb.getSheetAt(0)/>
<cfoutput>#sheet#</cfoutput>

Any ideas would be helpful:>)

Thanks,
Steph

1 Comments

Just to let everyone know, I had the same issue with POI not accepting Excel files where the top row was using filtering, In Excel 2007 (using the old XLS format) I just went to data and unticked "filter" and all worked ok, not sure if filtering is ok on other rows, didn't try it

1 Comments

This error
Object Instantiation Exception. An exception occurred when instantiating a java object

also happen if an Excel file has auto-filter on a column.

Hope this help someone.

3 Comments

Object Instantiation Exception Error.

Can anyone tell me how to remove or skip auto-filtering in excel using coldfusion. Found that the page has auto-filtering, but dont know exactly what to do. please help me. I need to fix this badly.

Thanks & regards.
Rafi

15,640 Comments

@Rafi,

From what I have read, this is a bug in the underlying POI Java library. I believe it is a filed bug and they are in the process of trying to fix it (I assume). And, since my tags just sit on top of the Java library, there is nothing that I can do about it.

3 Comments

Hi All

Thanks for ur reply Ben. I have two issues now.
1. As u know stacy some how managed to overcome the Object Instantiation Exception. by updating the new versions of poi-3.0...jar files into the lib of server. But i don't know how & wahere to update.

2. Can i use a file path like 'ftp://domain.data/file1.xls' in the
<cfset strFilePath = ExpandPath( "#url.file#" ) /> where
url.file = 'ftp://domain.data/file1.xls'

This is because i have to download a excel file from the ftp directory directly & feed the database.
It gives me an error at this line.

LOCAL.FileInputStream = CreateObject( "java", "java.io.FileInputStream" ).Init( ARGUMENTS.FilePath );

Please help me in these issues. I would be very thankfull to u.

Regards
Rafi

15,640 Comments

@Rafi,

You cannot go directly from FTP to Excel, at least not yet. You would need to save the file locally first, then read it into via POI.

3 Comments

Hi

Error: Object Instantiation Exception.

I did update the poi 3.0...jar files to the server lib. But still i get the Object Instantiation Exception. I am able to read and upload the excel file after deleting the first row (which should have a filter). But without deleting i am not able to. Is there any other solution.

Can anyone help me to get this fixed. I have been trying this for days nw. Please contact me on haja.rafi@gmail.com if u can guide me to get this rid off.

Thanks a lootttt !

14 Comments

Just a quick tip to anyone researching the 'Object Instantiation Exception' message (like I was a few minutes ago!) - Don't forget to check file permissions, especially on a *nix server - that was the root of my problem.

We now return you to your regular program! B->

All the best

</cliff>

6 Comments

Ben,

First of all, thank you for your site. I have learned a ton from reading your entries.

I am using your POIUtility.cfc amd have run into an issue with object instantiation. I thought it was a path issue, but I used the file exists function and it returned yes.

The error is tripping at the following code...

<cfset arrExcel = objPOIUtility.ReadExcel(
FilePath = strFilePath,
HasHeaderRow = true,
SheetIndex = 0
) />
<cfabort>

I have validated strFilePath, which is a valid path. Is there something I need to do on the server side or anything? Any help would be appreciated. If you need any more info, let me know.

15,640 Comments

@Clay,

What happens if you open up the target file in Excel and re-save it. If it works at that point, then there is something "odd" about the target file. Sometimes, if an Excel file is generated by a different 3rd party app, it has some features that don't jive with the POI library.

6 Comments

Ben...as usual, you are spot on. I opened it up, did a save as, re-uploaded and voila'...the magic of POI unfolded!

So it will be a good practice to do a save as from now on...thanks again for the assist and keep on coding!

15,640 Comments

@Clay,

It depends on where the document is coming from. Someone, a while back, discovered that POI can only deal with documents who's size is like a multiple of 255 B or something like that (I don't remember the exact number). Apparently, Excel will do this naturally, but 3rd party apps might not, so they bomb out when being read in via POI.

Where did this Excel document come from?

6 Comments

The document was exported from a 3rd party app...an online surveying product. It was an excel export of their results.

1 Comments

I'm researching the same thing and have one extra bit to add: it appears that the POI system can't read older (Excel 5.0) formatted files. If I save one of Ben's sample XLS files in the "Excel 5.0/95" format, I get this error. I do not know if the newer POI fixes this, but since I'm running on a shared environment, it's not likely to help me anyway.

Confusing the waters a bit more, my Open Office lists Excel 5.0 and Excel 95 as two different formats but Excel itself lists them together. I guess the point is 97/2000/XP works, older doesn't.

This might be why some people have success when they do a Save As.

15,640 Comments

@Mark,

Hmmm, interesting. I have not dealt much with the open office documents at all. Honestly, I haven't even really dealt much with the latest POI Java package yet.

1 Comments

Ben

I'm using your latest POIUtility.cfc along with all of the latest supporting files. Things are working very well when converting an Excel xx-2003 file (read: .xls). However, when I attempt, using the exact same code, to make the conversion on a Excel 2007 file (.xlsx) I end up getting the Object Instantiation Exception.

I've scoured the web for possible causes, moved files around, and I've come up with nothing. Any ideas?

Thanks in advance,
Heath

15,640 Comments

@Heath,

The problem is that the POI JAR file that ships with ColdFusion CF8 and earlier is *not* the most recent POI package. If you overwrite your JAR file with the newest one (or load it was a URL Class Loader), it should work with 2007 XLS files.

1 Comments

I am getting an Object Instantiation Exception.
Class not found: org.apache.poi.xssf.usermodel.XSSFWorkbook when trying to read a .xlsx file with the modified POIUtility.cfc. I have updated the jar files in CF8 to the 3.6 version and my file path is correct to the .xlsx file. Any ideas why this may be happenning?

1 Comments

@SGekko,

You may need to include the poi-ooxml-3.6.jar, and the other jars which come packaged from poi.apache.org.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel