aspose file tools*
The moose likes Testing and the fly likes Java.lang.ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Java.lang.ClassCastException" Watch "Java.lang.ClassCastException" New topic
Author

Java.lang.ClassCastException

Awet Haddis
Greenhorn

Joined: Jan 25, 2011
Posts: 11
Background: I am testing a class that will allow a user to upload data. I am using the Apache Commons FileUpload library.




I believe the compiler is having a problem with this statement:



Is there a way to specify the path to a FileItem so I don't have to cast a file as a FileItem? Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18909
    
    8

Awet Haddis wrote:Is there a way to specify the path to a FileItem so I don't have to cast a file as a FileItem? Thanks in advance.


Well, no you can't take just anything and cast it to a FileItem. If you want to simulate what the file upload would have produced, you're going to have to produce a mock version of FileItem and have it wrap your File, or something like that.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java.lang.ClassCastException