0

...

I'm just starting to learn how to work with a res folder in Java... res and src are both in the buildpath however when I try to use ResourceLoader from my programDriver in src, it isn't able to resolve into a type. How do you ''import'' from additional source folders?

This is the resource loader class, if at all relevant:

public class ResourceLoader {
private static ResourceLoader rl = new ResourceLoader();
public static Image getImage(String fileName)
{
    return Toolkit.getDefaultToolkit().getImage(rl.getClass().getResource("images/"+fileName));
}

}

Batman
  • 97
  • 9
  • 1
    Post code, not images of code. – AJNeufeld Apr 11 '16 at 03:26
  • I'll add it but I don't see how it will help, the code itself isn't the source of my problem as much as ignorance on how to import a Class from an additional src folder named "res" – Batman Apr 11 '16 at 03:27
  • 1
    More relevant might be the `ProgramDriver` code, since it is what is not able to find the `ResourceLoader` class. Anyone who is inclined to help you can't copy/paste the (ideally [mcve]) into their own IDE to attempt to debug the issue. – AJNeufeld Apr 11 '16 at 03:37
  • agreed, said code has been added, but the image is mostly for the file-structure of the project. I know *why* ResourceLoader can't be resolved into a type... it hasn't been imported. If it were in another package, ez, no problem, regular import statement... My problem is it's in another *source* folder (called "res") and I have no idea how to import it within this context. – Batman Apr 11 '16 at 03:40
  • The image of the file structure is useful, yes. But with a short snippets of both a main program (`ProgramDriver`) attempting to access `ResourceLoader` and a short `ResourceLoader` class, someone attempting to help could copy-paste into their IDE, setup similarly thanks to the project image, could immediately start to diagnose the issue, which is there is no way to ask Eclipse to import a `class` from a `package` with no name. Without it, the helper has to spend a minute or three creating both classes. You got an answer an hour after asking the question; it might have been a few minutes. – AJNeufeld Apr 11 '16 at 03:53
  • Possible duplicate of [How to import a class from default package](http://stackoverflow.com/questions/2193226/how-to-import-a-class-from-default-package) – AJNeufeld Apr 11 '16 at 03:59
  • 1
    Batman? really?? :-D – Sнаđошƒаӽ Apr 11 '16 at 04:45

1 Answers1

1

You cannot import classes from the "default" package. There is no import default.ResourceLoader statement. The use of the "default package" is discouraged for a reason; this is it (or one of them, anyway).

Move your ResourceLoader into it's own package, and then you can use an import statement in your ProgramDriver java file.

package resPkg;

public class ResourceLoader {
    // ...
}

package program;

import resPkg.ResourceLoader;

class ProgramDriver {
    // ...
}
AJNeufeld
  • 8,526
  • 1
  • 25
  • 44