Question

Error In Java While Executing the Program from CMD

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?


Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

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