Hello All, I am a B.tech final year student and working on an online Java Course. We are presently working on building the following instantiation code:
public class NameDriver
{
public static void main (String[] args)
{
//Instantiation
Name myName = new Name("Scott", "David", "Mitchell");
Name myName1 = new Name("David", "Mitchell");
Name myName2 = new Name("Mitchell");
Name noName;
System.out.println("myName: " + myName.toString());
}
}
I am using online java compiler from here and getting this error:
//Constructor Methods
public Name(String f, String m, String l)
{
first = f;
middle = m;
last = l;
}
public Name(String f, String l)
{
first = f;
middle = "";
last = l;
}
public Name(String l)
{
first = "";
middle = "";
last = l;
}
public Name()
{
first = "";
middle = "";
last = "";
}
public String toString()
{
return first + " " + middle + " " + last;
}
}
The result when I execute is the error message “Error: Could not find or load main class”.
The names of the Java files duplicate the name of the Main Class, so that doesn’t seem to be the problem. Can anyone suggest me the right path of this program?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
I’m familiar with how this specific online compiler works, but you should be able to just change the class name to public class Main and it should work.
Regarding what that error means, if your source code name is NameDriver.java, your compiled code will be NameDriver.class rather than Main.class.
Hope that this helps!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.