Questions tagged [getresource]

283 questions
1
vote
2 answers

Loading images/files inside jar

There are already heaps of answers to this problem. I have also tried a lot of them. I have not found a solution yet. I load some images within my project (Swing - ImageIcons). In the run dialog all of them are also displayed in my GUI. But after…
1
vote
1 answer

why FXMLLoader giving error when used to load a FXML file?

I was following a JavaFX tutorial and wrote the following code. All the required header files are imported. Main.java public class Main extends Application { @Override public void start(Stage primaryStage){ try { Parent root =…
1
vote
1 answer

How to get resource without context in Android?

If I have different resource names like elephant, tiger and cat. And I want to create a method accepting the resource name and return the drawable object. Then I wrote this public Drawable getDrawable(String name){ int defaultResId= …
Alston
  • 2,085
  • 5
  • 30
  • 49
1
vote
0 answers

getResourceAsStream working in eclipse, but not when run as applet in browser

I have an applet that needs to load saved data from a local text file that is in the eclipse package with the .java files. For use in this questions its name is "saveData.txt". When I run the applet through eclipse, everything works perfectly.…
Ross Larson
  • 2,357
  • 2
  • 27
  • 38
1
vote
0 answers

getSystemResource() vs getResource() with relevant ClassLoader

Question one: Is ClassLoader.getSystemResource("img.png"); exactly same as ClassLoader.getSystemClassLoader().getResource("img.png"); and what is the difference (which one to prefer?). I am expecting the answer "don't use either" (inside app…
Code Complete
  • 3,146
  • 1
  • 15
  • 38
1
vote
1 answer

how to read a file external to the jar // getResource issue with mysql dependency in pom

I would like to have a config file outside my jar. The config will be read and the program should behave accordingly. I tried to use: this.getClass().getResource( file_name ); But i ran into an issue with the pom dependencies. Below example…
aminator
  • 396
  • 7
  • 18
1
vote
0 answers

IntelliJ Idea + Gradle + class.getResource() returns null

I know, there are lots of similar question around here with similar problems, but after reading tons of posts, I cannot simply solve this issue. In my project I've already marked the resources folder as the Resources Root. Still, I'm getting null…
Davide3i
  • 1,035
  • 3
  • 15
  • 35
1
vote
1 answer

JAVA why only images works with class.getResource

I was searching for this problem on internet but did not find anything that would specifically dealing with this (there were some getResources() posts but nothing like my problem) so I am asking this question here now: I am using Netbeans8.0.2 and…
theoneiam
  • 11
  • 6
1
vote
2 answers

Java getResource not working in a .jar file

i am trying to export a pacman game i made from eclipse to a .jar package. The problem is that while everything runs fine on eclipse, when the .jar is exported, the resources i use dont load properly. I have them in a separate /res folder, which is…
user19955
  • 75
  • 1
  • 5
1
vote
1 answer

Java Resource Folder Name Versus Some Other Name

Is there something magic about a folder with the name 'resource' as opposed to something else. I have a file in 'resource' and when I try to load it, it works fine. ClassLoader loader=Thread.currentThread().getContextClassLoader(); InputStream…
Wt Riker
  • 514
  • 12
  • 24
1
vote
2 answers

Java: GetResource from different folder

I am trying to make 3 folders in a Javafx application. I have a Views folder which will contain my views, and I want to load an fxml file saved inside Views. I wrote this code inside start method: Parent root =…
Ayoub.A
  • 1,943
  • 3
  • 27
  • 34
1
vote
2 answers

getResource() to Path issue

Within my program i have a line of code: Path toRead = new File(getClass().getResource("/data.txt").toString()).toPath(); Whenever I try to run this I get an error: Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at…
Crimson Bloom
  • 287
  • 2
  • 13
1
vote
1 answer

Invalid path by getpath Function

In java i have to get the exact location of a image which is in a folder(Emoticon) under source directory inside a package but whenever i call String s=…
Shuvo
  • 29
  • 1
  • 5
1
vote
0 answers

Android - java.lang.RuntimeException: Unable to start receiver

I have wrote an app with custom Application class (MyApplication.java) and a BroadcastReceiver class (ConnectivityReceiver.java). However, I sometimes get bug reports from users stated that java.lang.RuntimeException: Unable to start receiver…
1
vote
1 answer

log4j properties file bundled into jar in spark app is ignored

I need to read a custom log4j.properties from src/resources and this is not working try{ val inStream :InputStream= className.this.getClass.getClassLoader.getResourceAsStream("log4j.properties"); logCfgProps.load(inStream) } catch { case e:…
Irene
  • 744
  • 1
  • 12
  • 36