aspose file tools*
The moose likes Java in General and the fly likes How to find a path as a string to a resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to find a path as a string to a resource" Watch "How to find a path as a string to a resource" New topic
Author

How to find a path as a string to a resource

Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601

Throws an exception, nullPointerException

I have my resources under


Any ideas?
Palraj Jayaraj
Ranch Hand

Joined: Jun 06, 2012
Posts: 35

My advice is to have the 'resources' folder under the default package.

and try the below code:

I hope this works
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
Palraj Jayaraj wrote:My advice is to have the 'resources' folder under the default package.

and try the below code:

I hope this works


Hi Palray,
I am afraid that still doesn't work. I have attached an image for your reference


[Thumbnail for resources folder.png]

Palraj Jayaraj
Ranch Hand

Joined: Jun 06, 2012
Posts: 35

Hey Jacky,

While creating a program, I had an excel sheet under a folder named 'a' in 'resources' folder, under 'src' folder'.

When I ran the program, I also got a Null-Pointer Exception.

Please refer to the attachments named:

in Folder a_Eclipse.jpg: https://docs.google.com/file/d/0BzcpOxYvgyz3b0cwNkpMdmFiZk0/edit?usp=sharing

in Folder a_Explorer.jpg: https://docs.google.com/file/d/0BzcpOxYvgyz3cVRJNk5hNGxveHc/edit?usp=sharing




But, when I had the same excel under the 'resources' folder itself (in 'src' folder), I did not get any errors.

Please refer the attachments named:

without Folder a_Eclipse.jpg: https://docs.google.com/file/d/0BzcpOxYvgyz3WjVQMFdMMENoQmM/edit?usp=sharing

without Folder a_Explorer.jpg: https://docs.google.com/file/d/0BzcpOxYvgyz3RHdsaDhNdW9HcUU/edit?usp=sharing





have the image under 'resources' and run the program. It should solve the problem.

It is weird though, I'm not aware of the root cause. But, it should solve your problem
Jacky Luk
Ranch Hand

Joined: Aug 02, 2012
Posts: 601
I did a little bit different from your version. But it did work



Thanks for your info
Jack
 
wood burning stoves
 
subject: How to find a path as a string to a resource