Java 无法解析ArrayUtil
我试图使用ArrayUtils从数组中删除一个项目,但我一直收到错误:Java 无法解析ArrayUtil,java,maven,visual-studio-code,import,Java,Maven,Visual Studio Code,Import,我试图使用ArrayUtils从数组中删除一个项目,但我一直收到错误: ArrayUtils cannot be resolvedJava(570425394) The type org.apache.commons.lang3.ArrayUtils is not accessibleJava(16778666) 这是该方法的外观: public void removeCard(int index) { ArrayUtils.remove(this.cardPaths, in
ArrayUtils cannot be resolvedJava(570425394)
The type org.apache.commons.lang3.ArrayUtils is not accessibleJava(16778666)
这是该方法的外观:
public void removeCard(int index) {
ArrayUtils.remove(this.cardPaths, index);
}
我已尝试导入org.apache.commons.lang3.ArrayUtils,但这给了我一个错误:
ArrayUtils cannot be resolvedJava(570425394)
The type org.apache.commons.lang3.ArrayUtils is not accessibleJava(16778666)
将依赖项添加到pom.xml文件也无法解决任何问题
我使用的是Java14.0.1、ApacheMaven3.5.2和VisualStudio代码请注意,您的代码没有任何作用 remove方法返回一个新数组-remove没有副作用;如果忽略它返回的内容,它除了浪费一些CPU和内存资源之外什么也不做。大概你想要: this.cardPaths=ArrayUtils.removethis.cardPaths,索引 此外,数组作为一个概念是复杂的,它们不能很好地串接,不能增长或收缩。如果您想要一个类似数组的概念,允许您添加和删除内容,java已经有了这个,它被称为ArrayList。那么您首先就不需要lang3了:
import java.util.List;
import java.util.ArrayList;
public class Deck {
private List<Card> cards = new ArrayList<Card>();
public void removeCard(int idx) {
return cards.remove(idx);
}
}
您是否添加了apache提供的lang3依赖项。如果已经添加,请尝试运行命令mvn clean installorg.apache.commons-lang33.9。清洁你的身体maven@Silverfang运行mvn clean install works:谢谢