Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (13.1k points)

I was trying to import class and I have created a program to get the messages but it is not working, below is the 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);

    }

}

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)

Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

Basically, this error shows up because the Message class is not available while compilation. In able to rectify the error you need to import the message class like:

import package1.package2.Message;

I hope this will help.

Want to become a Java expert? join Java Course now!!

Browse Categories

...