Different Folders & Java Compiling

Okay, so this is the first time I'm actually trying to make a java project where it actually follows guidelines, including some form of folder structure. However, I'm having trouble in actually compiling it, I have my src folder, which obviously contains the source code, but when I try to compile it, I run into a coupe of errors.

Within my src folder, it contains:

  1. main
  2. controller
  3. ui

Now just to keep it simple, let's say that in each of the 3 folders I've mentioned, they each contain 1 java class, in main I'm just trying to import things from the ui folder, so it looks something like this:

import src.ui.*;

Then in my ui folder, I have a class, let's call it UI.java and I have the package statement like this:

package ui; // Not to mention, I tried package src.ui and src.ui.UI

Then the same idea for the java file within the controller folder, any idea as to why this isn't working? Am I missing something really obvious? Like I said this is the first time I've tried to include a folder structure with a Java project, but from glancing at online material, I can't seem to get it to compile. When I try to compile the main folder, it just returns how package src.ui does not exist, then of course it points out how it can't locate anything to do with the files from the ui folder, as expected considering it's saying that the src.ui package does not exist.

No joke, this is my first time using the package statement in java, and this is the first time I've tried to import my own classes. I've use import for the likes of ArrayLists, and I know that it's case sensitive and what not. I feel like an idiot, and it's bugging me, I'm confident I'm just doing a stupid mistake. Can someone please just tell me where I'm going wrong?

Try replacing import src.ui.*; with import src.ui.whatYouspecificallyWant;

Although I don't really see that being the problem.

I have tried that and I had the exact same problem.... ?

I guess in a nutshell I'm trying to go back to the src directory, then go into one of the other 3 directories, then accessing the files in the other directories.

So is that even possible with a simple import statement? - Go back a directory, then into another, from the main parent?

I.e.

src contains: {main, controller, ui}

From ui I'd like to go to {src}. Then once I'm inside {src}, access {ui}, then get the file that's in the {ui} directory.

[Don't ask why I included curly brackets above, I thought it would add to formatting.]

I don't actually now if this is possible with just a simple import statement, like I've said, I've never used them before on my own work, I've only ever used them on built in classes.

Looking at the above image, I'd be trying to get something from Java.util to be able to access something in Java.lang, again, as an example, I find that it's easier to show what you're trying to do with a picture?

I only did one semester of Java and was not very good with it, you know better than I do unfortunately!

Dammit, my entire first year and a part of my second year is all done in Java, but we haven't even been taught how to use the import and package statements correctly....

Weird how I tried to compile it tonight, it worked, I swear down, I didn't change anything, could have a fault with my compiler or maybe I was trying to compile the wrong stuff. I feel 50/50 about this, I feel 99% sure I was compiling the right files, but computers don't really lie, do they? Probably me just being an idiot.

"Java" - some guy

1 Like