So in the last video, we created our common module and also created three packages and we moved the files
from the program the main project root source folder into the relevant packages and we've gone to the
start of the process of going through and getting things fixed so that we can actually run this application.
Now we've got a problem here an exception in application stop method.
If you scroll down here and see something in, click on that that tells us that the line is the parent
equals loader dot load.
And obviously on the previous line you can say there's a resource which is pointing to our main
xml file.
So the issue here is what previously it was using a relative path to our main dot xml
a sample path and the system was able to find that.
But now we're actually using a module.
So what we need to do is specify the path the leading slash so that the path is found at the start or
at the root level.
So basically we're telling the system to look at the root level and go down into a module that we've
created and actually stop trying to access the main xml file.
So that's why we're getting an exception basically it couldn't find that file.
I'm going to try running that again now.
And you can see now we're making good progress.
We've actually got to the stage now where we can actually run our application and if just click on something
to test that show albums clearly it's working ok.
So that's good, we're making progress.
Now you may or may not get this error.
So what I'm going to do is just open this file and close down this window for now.
put main.xml, now on line 10 here,
you have this fx controller.
you can see that it has been updated in our case to academy dot learn programming
dot UI dot controller,
you may find that's not updated.
It might still be me pointed to sample dot controller.
So if you get an error and it says something along the lines of sample controller make sure you do update it.
So it says academy don't learn programming dot UI.
dot controller, you can see in my case that it did automatically update and I was able to get the app working.
Essentially you know that you are on the right track if you're able to get the app working and see the
GUI interface.
And of course we just saw that working. At this point,
we need to now think about a module descriptor and in intelliJ we can easily add a module descriptor
just by pointing or right clicking on the source folder, come up here and do that up here in our module,
right click, click on new, come down and select module info dot java which of course is a module to script
to follow.
So when I select that you can see it's automatically created that line of code for us again.
So now that we've had that if we do nothing else this is going to result in a lot of compilation errors
since we've now got one Java module academy dot learn programming to come in to find in the module descriptor.
It's the one I mean now.
Just a simple line to come up here and run it.
You can see now we've got a lot of grief here.
IntelliJ's now coming up with lots of different areas purely by adding that module descriptor file
essentially and obviously in this case all these errors are related to modules, because clearly before
I added that module descriptor we were able to run the app.
So basically the problem is now we're using classes from JDK modules and we have to require those modules
go through an add that keyword to get things to work.
So stop looking at some of these error and say this first one here.
package javafx dot beans property is not visible.
So that means that we're using the package from the Java fx dot base module but we don't actually reading
that module.
And again to read a module to use a module in our modules we have to declare it with a requires statement.
Now we could add the requires statements manually or we can get the intelligence to help us with these errors.
So I just opened the album class, in the album class looking at the imports got this first one java
fx dot beans simple integer property line 3.
And again since this class is an inside module we can't use it until we require the module.
But we can do is moving the cursor to the line the error which obviously is his first one we can get
the bulb to appear.
So we're actually looking for the red red bulb to come up automatically.
But in this case he can say he's not coming up so what I can do is just select and come over here and
click on that.
And you say by doing that the red bulb does come up so you might have to click it a couple times but
eventually click on that and see the option that's come up in now and you can say that intimidate is
going to add the code first requires java
fx dot base directive to module-info.java and its simple as clicking on ADD
you can see the errors disappear.
And the compact compilation errors are resolved in this file.
So what actually happened to the module info file? We click that, let's have a look at that.
You can see now that requires statement has been added for java fx dot base
that means your module now uses or requires the module.
java fx dot base.
So the classes album and artists consequently, you see that was fixed, they no longer have
any compilation errors because that's been fixed because of the use of adding or in this case intelliJ
adding that required statement for us.
So let's now move onto the next one.
Next class was a double source and you can see that has got an error there.
So basically a classes from the Java dot sequel package.
So I need another requires statement in the module info file.
So this time just to show you the difference.
Let's go through and do that manually.
If you wanted to you'd come up here and click the red arrow.
It doesn't seem to appear just come up here and click on that will generally make the red line appear
the red bulb appear, so I could just click it and have it that way.
I'll just got back this time to module info on Java and what I'm going to do.
Just type this in, so requires
java.sql; you can see immediately when I type semi-colon that
the rest of errors disappeared.
And you can see that that's now fixed as well.
So moving on let's continue fixing these.
We've now got the next one which is the controller dot java.
Let's have a look at that.
And you say that we've got four things that need resolving here.
Let's go through them one by one.
I got to go back into that lawn to see where that works.
This time you can say that I've managed to get the bulb to appear so I'm going to click on that on the add,
and in terms of clicking you can if you want to get this to work for them to click there for arguments
like the red bulb won't come up so basically the last part of the package by clicking on that the red
bulbs appear.
So I'm going to click on that, click.
You can control and can I move up one level with this you might have a little bit of clicking or you
can come of here and click but we'll get through the process of getting that as well.
And you can say the areas have now disappeared from controllers.
Well and again looking back at module-info.java you can see these additional three lines that were
had there relating to Java fx.
Alright so it looks like we've resolved compilation errors and so let's
try running this again and see if we're getting anywhere, right click main, select run main.main
So I've still got an exception and initially I might look at that error and think that it doesn't make
a lot of sense but if you scroll down and have been looking at look here and read the text for this one
cannot access class academy dot learn programming dot UI
dot main module and reading because module academy dot learn programming does not export academy
dot learn programming
dot UI to module Java fx dot graphics.
So what that actually means is the java fx launcher can't launch our application because we didn't export
a package to the java fx dot graphics module.
Now if we don't export any package classes in the module that can't be accessed. So to export a package
we need to use the export statement and we talked about exports in a previous video,
so it's used to specify in the packages that are exported by the current module and you can see here
the other one that are in the module that they want to export.
As for module java fx dot graphics.
So what we can do is go back to our module info which I still get on screen.
and type exports academy dot learn programming dot UI to java fx.graphics,
semi colon. So by exporting a package to the java
fx. graphics module java fx launchers should be able to access a package and therefore run
the application. So let's try this.
We'll try running it again now.
Okay, you can see that we've got progress this time it's talking about academy dot learn programming
dor UI dot controller this time and scroll over to the right, java fx.xml.
So in other words you have to export the UI package to the module Java fx
xml, I get very similar to the previous error.
Let's go back and do that.
So we're going to do is just add a comma here which we can do java fx.xml
And the reason I'm putting a comma in the second module here is that
using another export statement for the same package in this case academy dot learn programming
for xml does lead to compilation error.
So if you do need to do that to export to multiple modules you do a comma and then the module name to do that.
So let's run that again. Okay, so I've still got an error.
So let's have a look. I'm just reading this.
And again you can see that the good thing about these errors are fairly descriptive.
To give you some pretty good hints as to what needs to be done here.
So you can see here the problem is the controller, artists table accessible module academy dot learn
the common opens academy learning programming UI to module java fx.xml
So in other words it's really being pretty blunt here saying we have to open the package to Java
fx.xml to that module.
Now the reason for that is because the fxml loader needs to set fields annotated with the
at fxml annotation, now that opening package the fxml loader can't load
the xml and inject or set those controller fields.
So what we need to do is to allow that is to type, but it's actually giving us the hint to type it.
so opens academy dot learn programming dot UI to java fx.fxml
Okay, let's run this again.
And you could see that the application ran, we got the GUI interface showing but again we've got another error now.
So leading got to the process and we got this problem here, this time its in the artist.
So again the process, let's have a look, doesn't open
academy.learnprogramming.common.java fx.base so pretty straightforward to have the result
that we need another open statement there, so opens the academy.
dot learnprogramming dot coma to java fx.base this time. Okay, let's run the application again I'll stop this
and run it again.
Its looking better, okay I finally got some progress here, let's select something, show albums.
clearly it's working now.
Alright so you could see that the process of converting to module is fairly intuitive.
If you take the time to read the exceptions, it's a logical process to follow.
And there are a few things that need to be done but ultimately you can say it the main work was actually
making sure the module info, the module descriptor file had the right options set in there.
Once we went through the process of looking at those errors and adding what we needed to to this file
this module descriptor file that got to the stage now where it's working.
Currently now we've got our code base inside a single module.
The current module info file has some redundant lines though,.
And this is because some modules that we require depend on other modules but we'll talk more about those lines later.
For now I'm going to leave you and see you in the next video because in that warm up we're going to
do is start separating the single module into multiple modules.
So I will see you in the next video.