Post Compile error, check Console? [duplicate]

2019-09-21 17:32发布

问题:

This question is an exact duplicate of:

  • Error Message: Int cann't be converted to type 3 answers

The error message is posted below along with with the actual code. The code is able to compile and run but instead of printing at the end I receive a pop up error message (screen shot below) but I don't understand what it means or why I am getting it. Can anyone help? Thanks!

public class Employee10
{   
    public static void main ( String args[] )
    {
        Employee e1 = new Employee();
        Employee[] arr = new Employee[2];

        int j = 0;

        for ( int i=0; i < 3; i++)
        {
            arr[0] = e1;

            String nameF = Input.getString("Please enter a First Name");
            String nameL = Input.getString("Please enter a Last Name");
            int Number = Input.getInt("Please enter an Employee Number");
            String Street = Input.getString("Please enter a Street address");
            String City = Input.getString("Please enter a City");
            String State = Input.getString("Please enter a State");
            double Zip = Input.getDouble("Please enter a Zip Code"); 
            int Month = Input.getInt("Please enter a Month");
            int Day = Input.getInt("Please enter a Day");
            int Year = Input.getInt("Please enter a Year");

            e1.setNumber(Number);
            e1.setName( new Name(nameF, nameL));
            e1.setAddress(new Address(Street, City, State, Zip));
            e1.setHireDate(new Date(Month, Day, Year));

            System.out.println(e1.getEmployeeString());


            arr[i] = e1;

        }   

        for ( j=0; j < arr.length; j++ )
        {
            System.out.println( arr[j].getEmployeeString() );
        }   
    }
}

ERROR MESSAGE: ( Unfortunately I am not able to embed a photo so I just have to type out the code so here it is):

The Java class file "Employee10.class" could not be launched. Check the Console for possible error messages.

What does all of this mean? Where is the Console I can check?

回答1:

TL;DR: The console depends on what software you're using to run your code (we call these Integrated Development Environments, or IDEs). If you tell us what software you're using, we can help.

Long answer: There are generally 2 kinds of errors - compile time and runtime. Compile time errors are usually told to you by your IDE. These are things like misspelling keywords ("itn" instead of "int", "tSring" instead of "String", etc) and missing semicolons. Runtime errors are a different beast. These occur when your program actually runs. One example is lets say you have an array of size 10. If you try to look at the eleventh element, when you run your program, it will fail. These errors are the ones that usually show up in the console in the form of a stack trace - some message telling you which functions were called and where the specific error is from.



回答2:

If you are using a very basic IDE like BlueJ(since you are a beginner),I would suggest you to place something like System.out.println("Beginning program"); or something similar which prints something onto the console.Make this the first statement in main.Now console could be considered as the place were you would see your output statements displayed(raw definition).Could be considered as a display window. I used BlueJ long back when I was learning java and it never triggered the program until there was something to print on to the console.It always lookes for a print statement to begin with.

And the strangest part was-It never required a string array as an argument in the main function.I was surprised when I switched to eclipse and the program didn't compile without the argument in main.So things could be strange with some very basic IDEs.

I would suggest that you try out this solution and also try to use a good IDE like eclipse or netbeans.These IDEs are highly professional and would give you immediate and great ideas on errors that occur in a program.