简体   繁体   English

包中无法识别Java类

[英]Java class not recognized within package

My friend and I are using GitHub to collaborate on a project, and I just downloaded a package he had. 我和我的朋友正在使用GitHub进行项目协作,而我刚刚下载了他拥有的软件包。 He wrote it in NetBeans and I'm using it in Eclipse. 他用NetBeans编写了代码,而我正在Eclipse中使用它。 Four of the classes in the package have the regular icon, a white page with a blue J. But three others have a white page, but there's an outline of a blue J instead of a filled J. The four regular classes all expand into class and then method/property trees, but the three odd classes don't expand at all in the Package Explorer. 程序包中的四个类具有常规图标,白页带有蓝色J。但是其他三个类具有白页,但是有一个蓝色J的轮廓,而不是填充的J。这四个常规类都扩展为类然后是方法/属性树,但是三个奇数类在Package Explorer中根本不会扩展。 When I try to reference one of the odd classes in a regular one, ie 当我尝试在常规类中引用其中一个奇数类时,即

List<Reminder> list = new ArrayList<Reminder>();

It puts a red underline under the class Reminder and when I hover over it with my cursor, it tells me to add an import statement, but when I click on where it says that it doesn't add the import statement. 它将红色下划线放在“ Reminder ”类下,当我将鼠标悬停在其下时,它告诉我添加导入语句,但是当我单击该行时,它说它没有添加导入语句。 When I try to type in the import statement myself, ie 当我尝试自己输入导入语句时,即

import MobiTech.PlaceSaver.Reminder;

It says the import can not be resolved. 它说导入无法解决。 The syntax used for declaring the class seems to be correct: 用于声明该类的语法似乎是正确的:

public class Reminder
{
public Location location;
public String message;
//Reminder radius in meters
double radius = 1.0;

public Reminder()
{
}
public Reminder(Location l, String m)
{
    message = m;
    location = l;
}

public Reminder(Location l, String m, int r)
{
    message = m;
    location = l;
    radius = r;
}

I don't see what's going on, any ideas? 我不知道发生了什么,有什么想法吗?

You should take a look at this . 你应该看看这个 It seems the "outline of the blue J" is the second one on that list, which means that Java file is not on a build path. 似乎“蓝色J的轮廓”是该列表上的第二个轮廓,这意味着Java文件不在构建路径上。 Follow this guide to add them to your project's build path. 请按照指南将其添加到项目的构建路径。

Edit: or this one, that one's nice and simple. 编辑:或者这个 ,那很简单。 Go down to "2. Adding existing files to the project". 转到“ 2.将现有文件添加到项目”。

Edit 2: As the OP said in the comment below, to add the existing code to the project, right click on it (the package or directory) in the package explorer, then select "Build Path -> Include". 编辑2:如OP在下面的注释中所述,要将现有代码添加到项目中,请在包资源管理器中右键单击它(包或目录),然后选择“构建路径->包含”。

I know this is an old question, but I just had a very similar problem. 我知道这是一个老问题,但是我有一个非常类似的问题。 I came across this forum post: http://www.eclipse.org/forums/index.php/t/88625/ . 我遇到了这个论坛帖子: http : //www.eclipse.org/forums/index.php/t/88625/

As the post suggested I clicked Project->Clean, and all the unresolved type errors disappeared. 正如该帖子所建议的那样,我单击了Project-> Clean,所有未解决的类型错误都消失了。

same happens for me here. 我在这里也遇到同样的情况。 It turns out just when the class was not built in the bin folder. 事实证明,该类不是在bin文件夹中构建的。 Check your bin or target folder. 检查您的bin或目标文件夹。 ~

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

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