Questions tagged [getresource]
283 questions
2
votes
3 answers
What does getClass().getResource() point to?
In Java, Eclipse, what location does this line of code refer to?
this.getClass().getResource()
Does it give me the project folder? Or the package folder? Or anything else?
How exactly should one work with this?

Aviv Cohn
- 15,543
- 25
- 68
- 131
2
votes
1 answer
NullPointerException in getResources
I have activity and class. In activity I do HTTP GET request (HttpClass.java), then in GetMethod.java I do Asynctask. In onPostExecute function I want to return to activity and parse data with JSON. It works, but when I try to create layout with…

Askar Zaitov
- 283
- 1
- 6
- 15
2
votes
2 answers
Java applet can't find resources in jar if run locally
Problem: Java applet can't load resources located inside its jar when run locally on windows platforms. The same applet can load the resources if it is launched from a web server instead of launched locally or if it's launched locally on a linux…

Jim
- 31
- 1
- 4
2
votes
2 answers
Implementation of getResources() Android
I have just started learning android programming and I came up with a doubt about the method getResources().
I noticed that when I create a Resources object all I have to do is:
Resources res = getResources();
The first doubt is the following why do…

zer0uno
- 7,521
- 13
- 57
- 86
2
votes
1 answer
Copying a binary file outside of a jar
I have an exe packaged inside my jar file and I am trying to copy it to a temporary location so that i can run it using Desktop.browse(), to do this I set up a scanner with the input stream constructor using class.getResourceAsStream, and then with…

Josh Sobel
- 1,268
- 3
- 14
- 27
2
votes
1 answer
getClass().getResource() Exception?
I'm trying to learn how to add images to my JFrame. I'm adequate in GUI, but I simply cannot understand why this doesn't work.
I have arrays set so that I can I can do multiple images, in case you wondering.
(1) MY problem is the…

Danny Simons
- 35
- 1
- 7
2
votes
2 answers
getResource() of another class
I am having a class A which gets a configuration file doing:
this.getClass().getResource("cfgFile");
Now I created a new class B who needs A's cfgFile. Right now I am doing:
A.class.getResource("cfgFile");
But it doesn't feel right.
I was willing…

Macarse
- 91,829
- 44
- 175
- 230
2
votes
4 answers
ModX Revo: getResources not sorting by menu index
I want to order my resources by menu index and have the following code:
[[!getResources? &parents=`50` &sortdir=`ASC` &sortby=`menuindex` &limit=`100` &includeTVs=`1` &processTVs=`1` &tpl=`temp` ]]
But the sortby just isn't working.
Would anyone…

MeltingDog
- 14,310
- 43
- 165
- 295
2
votes
2 answers
Java - getResource fails on csv files
I have a unit test package in which I keep a few txt files. These get loaded via getClass().getResource(file); call and it works just fine. I added into the same folder a csv file, and if I supply its name as the parameter i.e.…

Bober02
- 15,034
- 31
- 92
- 178
2
votes
1 answer
Getting resource from OSGi bundle
I try to get file as resource from bundle jar using Felix/OSGi.
I have read No access to Bundle Resource/File (OSGi) and How to reference an included file in OSGi bundle when performing java.io.File or FileInputStream but I can't understand how to…

Arthur
- 3,253
- 7
- 43
- 75
2
votes
1 answer
getClass().getResource() returns null in deployment
The following code is running fine when i run the application from netbeans
ThumbnailLabel lblImg =new ThumbnailLabel(new javax.swing.ImageIcon(
getClass().getResource("/jewelleryerpapplication/GUI/resources/NoPicture.png")));
Then I clean…

Syed Muhammad Mubashir
- 966
- 6
- 23
- 51
1
vote
2 answers
getResource("/some.jar") returns null, although "some.jar" exists in getURLs()
After hours I am giving up on debugging the following:
This works:
URL[] urls = ((URLClassLoader) MyClass.class.getClassLoader()).getURLs();
URL myURL = null;
for (URL url : urls) {
if (url.getPath().endsWith("some.jar")) {
…

Daniel K
- 2,977
- 2
- 24
- 23
1
vote
1 answer
How to getResource from jar with compiled groovy classes?
I have the groovy script. I compiled it with groovyc and jar'ed classes. So script1.class is in jar's root. And I put some file foo.bar in jas's root too.
How do I get that file with getResource? Which ClassLoader should I use? And how do I get this…

guai
- 780
- 1
- 12
- 29
1
vote
2 answers
Get File from Main.class.getResource()
I am making a small game in Java. For this game I just added sounds. So I want to have all my images and audio files in the jar. For pictures this was easy:
new ImageIcon(Main.class.getResource("images/machgd2.png")).getImage()
But for audio it…

totokaka
- 2,244
- 1
- 21
- 33
1
vote
1 answer
How to access files in other packages without using a dummy class
I am actually loading OWL files in my java web app with the following code:
InputStream is = Dummy.class.getResourceAsStream("content.owl");
I created Dummy.class in the same package as content.owl is to get access to this file.
Is there a…

Martin Schlagnitweit
- 2,042
- 6
- 26
- 42