File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes class.getResource Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "class.getResource Problem" Watch "class.getResource Problem" New topic

class.getResource Problem

Dipse smith

Joined: Mar 12, 2008
Posts: 5
My program has a very simple help system that uses HTML files. These files are loaded as follows:

This worked fine when developing the program. The html pages loaded and were displayed in a JEditorPane, but when i put the classes and the other files needed (including the help files) into a jar file the html files cannot be found and i get a invalid url error. What am i doing wrong?
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Inside the JAR file, in the same folder as the HelpDialog.class file, is the help folder there as well?

Another thing, with resources you can just use / on all platforms. No need for the use of File.separator there.

How To Ask Questions How To Answer Questions
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

What happens if you change your resource path to "/help..."?

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Dipse smith

Joined: Mar 12, 2008
Posts: 5
I have tried all your suggestions and have also tried a few other things in the last few days and have been unable to get it to work. The program is a petrol pump simulator and is a project for school. The help files are located in the jar file in a folder called help. The problem i believe is to do with the fact i am accessing them as a URL because i also have a txt file in the jar file in a folder called data which the program can read and write from perfectly well. So at the moment i am stumped. Any suggestions are welcome, i am willing to look at other method other than using URL url = HelpDialog.class.getResource("help"+File.separator+children[i].getName());
TO get the HTML files so they can be displayed in the JEditorDialog.
Thanks so far for the help and for any future help.
Dipse smith

Joined: Mar 12, 2008
Posts: 5
Still have not found a solution to the problem does anyone know of another way to display HTML documents in java?
I agree. Here's the link:
subject: class.getResource Problem
It's not a secret anymore!