【发布时间】:2017-07-12 06:54:40
【问题描述】:
我正在尝试调用我自制的“过滤器”类的方法,但编译器找不到该方法。
这有点棘手,因为我在 Eclipse 中编写代码,一切似乎都很好。但是我必须将我的代码复制到另一个软件中并在那里编译。另一方面,这个编译器找不到我的方法。
我假设 Eclipse 编译器可能“允许”更多我什至不知道的错误。然而,另一个编译器与他们斗争。
这是“其他”编译器打印的错误代码:
C:\Program Files\Enomic\enomic-server\data\rules\testcompileboehmch\CodeTest.java:77: error: cannot find symbol filt.setHasRemoved(true);
symbol: method setHasRemoved(boolean)
location: variable filt of type tms.Filter
我不知道为什么我的课程不正确。正如上面在 Eclipse 中所说,一切正常。
CodeTest 类(精简到重要部分):
package tms;
import tms.Filter;
import java.util.*;
Filter filt = new Filter();
filt.setHasRemoved(true);//cannot be found
我的过滤器类:
package tms;
import java.util.ArrayList;
import java.util.List;
public class Filter {
private List<Object> remainingList;
private List<Object> removedList;
private Object typ;
private boolean hasRemoved;
public Filter()
{
this.remainingList = new ArrayList<Object>();
this.removedList = new ArrayList<Object>();
this.typ = new Object();
this.hasRemoved = false;
}
public Filter(List<Object> remaining, List<Object> removed, Object typ, boolean hasRemoved)
{
this.remainingList = new ArrayList<>();
if(remaining != null)
{
this.remainingList.addAll(remaining);
}
this.removedList = new ArrayList<>();
if(removed != null)
{
this.removedList.addAll(removed);
}
this.typ = typ;
this.hasRemoved = hasRemoved;
}
//Set-Methoden
public void setRemainingList(List<Object> list)
{
this.remainingList.clear();
this.remainingList.addAll(list);
}
public void setRemovedList(List<Object> list)
{
this.removedList.clear();
this.removedList.addAll(list);
}
public void setTyp(Object val)
{
this.typ = val;
}
public void setHasRemoved(boolean val)
{
this.hasRemoved = val;
}
//Get-Methoden
public List<Object> getRemainingList()
{
return this.remainingList;
}
public List<Object> getRemovedList()
{
return this.removedList;
}
public Object getTyp()
{
return this.typ;
}
public boolean getHasRemoved()
{
return this.hasRemoved;
}
}
我真的不知道为什么这不起作用。有什么我看不到的错误吗?
【问题讨论】:
-
检查您的导入。
-
您是否使用了正确的
Filter类?例如。导入正确吗?自从添加了这些方法后,你确定重新编译了Filter吗? -
你的类路径中有两个版本的类吗?
-
导入工作正常。 “Filter filt = new Filter()”行有效,因此该类被识别
-
有很多类叫做
Filter- 你可能弄错了 - 向我们展示你的导入语句。
标签: java eclipse compiler-errors