Java 在另一个文件中找不到类
我查看了其他用户提出的类似问题的答案,但仍然不明白为什么我无法找到我创建的两个类的符号错误 我的头发看起来像这样Java 在另一个文件中找不到类,java,cannot-find-symbol,Java,Cannot Find Symbol,我查看了其他用户提出的类似问题的答案,但仍然不明白为什么我无法找到我创建的两个类的符号错误 我的头发看起来像这样 StacksAndQueuesProblems/threestacks 在threestacks目录中,我有以下.java文件: FullStackException.java fixedMultiStack.java 从StacksAndQueuesProblems目录中,我试图执行javacThreeStacks/*.java 但是,我得到以下错误: threesta
StacksAndQueuesProblems/threestacks
在threestacks
目录中,我有以下.java
文件:
FullStackException.java
fixedMultiStack.java
从StacksAndQueuesProblems
目录中,我试图执行javacThreeStacks/*.java
但是,我得到以下错误:
threestacks/fixedMultiStack.java:20: error: cannot find symbol
throw FullStackException("ERR: That stack is full!");
^
FullStackException.java
package threestacks;
public class FullStackException extends Exception {
public FullStackException(String message) {
super(message);
}
}
fixedMultiStack.java
package threestacks;
class fixedMultiStack {
private int numberOfStacks = 3;
private int stackCapacity;
private int[] values;
private int[] sizes;
public fixedMultiStack(int stackCapacity) {
this.stackCapacity = stackCapacity;
values = new int[stackCapacity * numberOfStacks]; // Holds all 3 stacks
sizes = new int[numberOfStacks+1]; // Holds the number of items in each stack
}
/* push value onto stack */
public void push(int stackNum, int value) throws FullStackException {
/* check if we have space on the stack for the element */
if (isFull(stackNum)) {
throw FullStackException("ERR: That stack is full!");
}
/* increment stack pointer and then insert the value */
sizes[stackNum]++; // Increment the number of items for that stack
values[indexOfTop(stackNum)] = value; // Insert the value into the array
}
/* Pop item from the stack */
public void pop(int stackNum) {
if (isEmpty(stackNum)) {
throw new EmptyStackException();
}
/* Retreive the value and decrement the stack pointer */
int topIndex = indexOfTop(stackNum);
int value = values[topIndex]; //Get top
values[topIndex] = 0; // Clear
sizes[stackNum]--; // Decrement the size of the stack
}
/* Return top element */
public int peek(int stackNum) {
if (isEmpty(stackNum)) {
throw new EmptyStackException();
}
int topIndex = indexOfTop(stackNum);
int value = values[topIndex];
return value;
}
/* Return if stack is empty */
public boolean isEmpty(int stackNum) {
return sizes[stackNum] == 0;
}
/* Return if stack is full */
public boolean isFull(int stackNum) {
return sizes[stackNum] == stackCapacity;
}
/* Returns index of top of stack */
public int indexOfTop(int stackNum) {
return ((stackNum -1) * stackCapacity + sizes[stackNum] - 1);
}
}
文件fixedMultiStack.java中存在编译错误。应该是
throw new FullStackException("ERR: That stack is full!");
这不应该是
抛出新的SomethingException(“somestring”)代码>?你似乎忘记了新的
。投票结束更像是一个印刷错误。谢谢你的回答,但这值得投反对票吗?是的,进一步考虑,你是对的,没有。否决票被删除。但是,错误消息会准确地告诉您问题所在,因此在将来,您需要更仔细地校对相关行,以避免类似的粗心错误。祝你好运