简体   繁体   English

Eclipse上的Java包名称编译问题

[英]Java package name compilation issue on Eclipse

I have an issue on Eclipse regarding compiling with a Java package name (TurtleGraphics). 我在Eclipse上有一个关于使用Java包名称(TurtleGraphics)进行编译的问题。 This is my code: 这是我的代码:

package TurtleGraphics;

import TurtleGraphics.KeyboardReader;

public class Loops21 {

    public static void main(String[] args) {
        // Navo

        int count = 1, sum = 0;
        KeyboardReader reader = new KeyboardReader();
        while(count<=50)
        {
            sum = sum + count;
            System.out.println(count + "\t" + sum );
            count++;
        }

    }

}

The problem is that it has not been recognizing KeyboardReader. 问题在于它尚未识别KeyboardReader。 I have always been using this but all of a sudden I have a problem. 我一直在使用它,但突然之间我遇到了问题。 This is what it says: 它是这样说的:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The declared package "TurtleGraphics" does not match the expected package ""
    at KeyboardReader.<init>(KeyboardReader.java:5)
    at Loops21.main(Loops21.java:9)

Thank you for all the help. 感谢您的所有帮助。 I have a solution which is reinstalling Eclipse, but I don't know if that will work. 我有一个重新安装Eclipse的解决方案,但是我不知道这样是否可行。

Assuming your source file Loops21.java starts with: 假设您的源文件Loops21.java以以下内容开头:

package TurtleGraphics;

import TurtleGraphics.KeyboardReader;

public class Loops21 {

And the file KeyboardReader.java starts with: 文件KeyboardReader.java的开头是:

package TurtleGraphics;

Then the following worked for me: 然后以下对我有用:

> mkdir TurtleGraphics
> mv KeyboardReader.java TurtleGraphics
> mv Loops21.java TurtleGraphics
> javac TurtleGraphics/Loops21.java 
> java TurtleGraphics/Loops21
1   1
2   3
3   6
...
48  1176
49  1225
50  1275
> 

The dot in the import path name represents directory structure so you need to build that directory structure. 导入路径名称中的点代表目录结构,因此您需要构建该目录结构。 The above is a command line example, you need to do the Eclipse equivalent. 上面是一个命令行示例,您需要做等效的Eclipse。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM