Exception in thread “main” java.lang.Error: Unresolved compilation problems

I am having a problem importing classes and setting variables and I need help with a test program I am doing. So I am testing out a program that just simply outputs what your input was and puts a time stamp ( Like Skype ). I am having an issue getting the message and time variable type to work! Here is my code:

class Test {
    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        Message messageObject = new Message ();
        Time timeObject = new Time ();

        System.out.println("Enter your message here: ");
        String message = input.nextLine();

        messageObject.simpleMessage(message);
        timeObject.getTime();
    }

    void simpleMessage(String message) {
        System.out.println(message + time);
    }
}

And here is my error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Message cannot be resolved to a type
Message cannot be resolved to a type
The constructor Time() is undefined

at Test.main(Test.java:8)

5 Answers

Your problem is in this line: Message messageObject = new Message ();
This error says that the Message class is not known at compile time.

So you need to import the Message class.

Something like this:

import package1.package2.Message;

Check this out.

http://docs.oracle.com/javase/tutorial/java/package/usepkgs.html

Two possibilities here. Java Version incompatible or import

You have to Import the Scanner and Timer Package Properly using the java.util classes.

import java.util.Scanner;
import java.util.Timer;

For this error:

Exception in thread “main” java.lang.Error: Unresolved compilation problems:

There are problems with your import or package name.
You can delete the package name or fix import errors

Check Following : 1) Package names 2) Import Statements (import every required packages) 3) Proper set of braces ,i.e { } 4) Check Syntax too.. i.e semicolons,commas,etc.

Leave a Reply

Your email address will not be published. Required fields are marked *