线程“main”中的异常java.lang.Error:未解决的编译问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20961074/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 05:34:56  来源:igfitidea点击:

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

javatestingtimeimportmessage

提问by GamerzKing

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:

我在导入类和设置变量时遇到问题,我需要有关我正在执行的测试程序的帮助。所以我正在测试一个程序,它只是简单地输出您的输入内容并加上时间戳(如 Skype )。我在获取消息和时间变量类型时遇到问题!这是我的代码:

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)

采纳答案by peter.petrov

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

您的问题出在这一行:Message messageObject = new Message ();
此错误表示Message该类在编译时未知。

So you need to import the Message class.

所以你需要导入 Message 类。

Something like this:

像这样的东西:

import package1.package2.Message;

Check this out.

看一下这个。

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

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

回答by Kishor Poojari

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

您必须使用 java.util 类正确导入扫描仪和计时器包。

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

回答by Yang

For this error:

对于此错误:

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

线程“main”中的异常 java.lang.Error:未解决的编译问题:

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

您的导入或包名称有问题。
您可以删除包名称或修复导入错误

回答by NPE

Two possibilities here. Java Version incompatible or import

这里有两种可能。Java 版本不兼容或导入

回答by Shah Dharmik

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.

检查以下内容:1)包名称 2)导入语句(导入每个必需的包) 3)正确的大括号,即 {} 4)检查语法也......即分号,逗号等。