Home > OS >  How do I create packages in Visual Studio Code that will handle my Java dependencies?
How do I create packages in Visual Studio Code that will handle my Java dependencies?

Time:11-23

I am working with objects and creating constructors such as this:

Employee employee1 = new Employee();

When I go to run each individual constructor, I get this error:

Employee cannot be resolved to a type

My instructor informed me that this error had to do with Visual Studio Code and having to create packages within the project. I scoured the internet for tips on how to do this and even attempted to use Maven to set up the project but I was unable to produce any results thus far.

CodePudding user response:

Use an IDE that is more aligned to Java such as Eclipse or Apache Netbeans and create a self contained project within there. Visual Studio Code is a glorified text editor with a million plugins of varying quality. Jack of all trades, master of none etc.

Choose the right tools for the job rather than trying to hammer a nail into the wall with a shoe.

I'm sure other answers will come in different opinions and with the specific answer you're looking for...

CodePudding user response:

Solved!

I just had to open my classes/methods along with my driver, which was the code I had in the example.

Hope that clears things up for anyone having the same issue.

CodePudding user response:

First you have to create a class to represent Employee, and inside of the class you will have your public constructor, like this:

public class Employee {
    // class members
    public Employee() {
    // constructor code
    }
}

From here you will be able to call the public constructor for the Employee class like so:

Employee employee1 = new Employee();
  • Related