1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java program won't compile

  1. Mar 10, 2008 #1
    Supposed to make a program that displays an entered name and date, etc, but it won't run.

    Code (Text):
    import java.util.*;
    import java.text.*;
    import javax.swing.*;

    public class ch2NameAndDate {


        public static void main(String[] args) {
            // Input the first, middle, and last name
            // Display the name and the date.
            String firstNameString, middleNameString, lastNameString;
           
            //Create a Scanner object
            Scanner inputScanner = new Scanner(System.in);
           
            //Objects needed for date.
            Date todayDate = new Date();
            SimpleDateFormat formattingSimpleDateFormat=
                new SimpleDateFormat("MMMM dd yyyy");
           
            //Input the data
            System.out.print("enter your First name  ");
            firstNameString = inputScanner.next();
            //firstNameString = JOptionPane.showInputDialog("Enter your First Name");
           
            //middleNameString enter middle name.
            System.out.print("enter your Middle name  ");
            middleNameString = inputScanner.next();

           
            //lastNameString = JOptionPane.showInputDialog("enter your Last name");
            System.out.print("Enter your Last name ");
            lastNameString = inputScanner.next();
           
            //Print out first, middle, and last name with date.  
            System.out.println("Hello" + lastNameString + "," + " " + firstNameString + " " + str.substring(0); + "." + "today is " +
            formattingSimpleDateFormat.format(todayDate));
        }

    }
    I tried running it and eclipse said:
    Code (Text):
    java.lang.NoClassDefFoundError: NameAndDate
    Exception in thread "main"
    what's wrong? I thought I declared the class in the code.
     
  2. jcsd
  3. Mar 10, 2008 #2

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Let me guess -- you saved the file as NameAndDate.java? If so, then it expects to find a class named NameAndDate in the file... and that's not the name of the class you defined.
     
  4. Mar 10, 2008 #3
    Ahh, thanks. That fixed the problem.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Java program won't compile
  1. Java programming (Replies: 4)

  2. Java compiler error (Replies: 3)

  3. Java program (Replies: 3)

Loading...