?
Solved

null value returned for the url

Posted on 2011-09-08
6
Medium Priority
?
249 Views
Last Modified: 2012-05-12
We are using server side java with blazeDS for our current project, and are using class.getClassLoader().getResource("fileName"), but we are getting a null value returned for the url.  We have placed "fileName" with the .class files on the server, but it seems like it is unable to find the file.  Is there something we are missing, maybe in setting up the project?


thanks
0
Comment
Question by:anotherfn
  • 4
6 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36505748
Is it inside the WEB-INF folder?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36505756
If you use

this.getClass().getClassLoader().getResource("fileName")

then my understanding is that you should be putting your class inside the pacjage of class of your instance this - are you doing it this way ?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36505905
I'm sorry I was not right in my previous post - actually

URL url = this.getClass().getClassLoader().getResource("fileName");

This will be looking at the root of your classpath for class of intsnce this


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 36505926

So if your class of this is
com.company.pack.MyClass

then your MyClass.class will be in the fiolder

com/company/pack

however this

URL url = this.getClass().getClassLoader().getResource("fileName.txt");

will be looking for file  fileName.txt
in the folder above com

if you put it alongside with class fiile MyClass
the you shoud say:

URL url = this.getClass().getClassLoader().getResource("com/company/pack/fileName.txt");

Otherwise it returns null

I juts tested it and it works that way





0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36505940
I think it should work the same way, no matter if it is in regular applcation or in J2EE or app server
or anything because this is how these methods should work according to specification
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36506975
Please post your code and tell us where you file is
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Convert websphere application server default chained Certificates from 1024 to 2048 keysize or higher size and also you can change signatureAlgorithm . Please make sure Websphere Application Server fixpack 7.0.0.23 or Above. The following steps a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question