Java 无法在包内找到或加载主类

Java 无法在包内找到或加载主类,java,linked-list,package,Java,Linked List,Package,我是来自Python和C的Java新手,在运行这段代码时遇到了问题。要编译,我正在使用: javac SLList.java java SLList 为了运行,我使用了: javac SLList.java java SLList 这就是我的问题所在。我怀疑问题在于代码在包中,我必须使用不同的运行指令。以下提供了代码以供参考: package ods; import java.util.AbstractQueue; import java.util.Iterator; import j

我是来自Python和C的Java新手,在运行这段代码时遇到了问题。要编译,我正在使用:

javac SLList.java
java SLList
为了运行,我使用了:

javac SLList.java
java SLList
这就是我的问题所在。我怀疑问题在于代码在包中,我必须使用不同的运行指令。以下提供了代码以供参考:

package ods;

import java.util.AbstractQueue;
import java.util.Iterator;
import java.util.Queue;

/**
 * An implementation of a FIFO Queue as a singly-linked list.
 * This also includes the stack operations push and pop, which
 * operate on the head of the queue
 * @author morin
 *
 * @param <T> the class of objects stored in the queue
 */
public class SLList<T> extends AbstractQueue<T> {
    class Node {
        T x;
        Node next;
    }

    /**
     * Front of the queue
     */
    Node head;

    /**
     * Tail of the queue
     */
    Node tail;

    /**
     * The number of elements in the queue
     */
    int n;

    public Iterator<T> iterator() {
        class SLIterator implements Iterator<T> {
            protected Node p;

            public SLIterator() {
                p = head;
            }
            public boolean hasNext() {
                return p != null;
            }
            public T next() {
                T x = p.x;
                p = p.next;
                return x;
            }
            public void remove() {
                throw new UnsupportedOperationException();
            }
        }
        return new SLIterator();
    }

    @Override
    public int size() {
        // TODO Auto-generated method stub
        return n;
    }

    public boolean add(T x) {
        Node u = new Node();
        u.x = x;
        if (n == 0) {
            head = u;
        } else {
            tail.next = u;
        }
        tail = u;
        n++;
        return true;
    }

    public boolean offer(T x) {
        return add(x);
    }

    @Override
    public T peek() {
        return head.x;
    }

    public T poll() {
        if (n == 0)
            return null;
        T x = head.x;
        head = head.next;
        if (--n == 0)
            tail = null;
        return x;
    }

    /**
     * Stack push operation - push x onto the head of the list
     * @param x the element to push onto the stack
     * @return x
     */
    public T push(T x) {
        Node u = new Node();
        u.x = x;
        u.next = head;
        head = u;
        if (n == 0)
            tail = u;
        n++;
        return x;
    }

    protected void deleteNext(Node u) {
        if (u.next == tail)
            tail = u;
        u.next = u.next.next;
    }

    protected void addAfter(Node u, Node v) {
        v = u.next.next;
        u.next = v;
        if (u == tail) 
            tail = v;
    }

    protected Node getNode(int i) {
        Node u = head;
        for (int j = 0; j < i; j++)
            u = u.next;
        return u;
    }

    /**
     * Stack pop operation - pop off the head of the list
     * @return the element popped off 
     */
    public T remove() {
        if (n == 0) return null;
        T x = head.x;
        head = head.next;
        if (--n == 0) tail = null;
        return x;
    }   

    public T pop() {
        if (n == 0) return null;
        T x = head.x;
        head = head.next;
        if (--n == 0) tail = null;
        return x;
    }   


    public static void main(String[] args) {
        Queue<Integer> q = new SLList<Integer>();
        for (int i = 0; i < 100; i++) {
            q.add(i);
        }
        System.out.println(q);
        for (int i = 0; i < 50; i++) {
            q.remove();
        }
        System.out.println(q);
        for (int i = 100; i < 200; i++) {
            q.add(i);
        }
        System.out.println(q);
        for (int i = 0; i < 50; i++) {
            q.remove();
        }
        System.out.println(q);
        while (!q.isEmpty()) {
            q.remove();
        }
        System.out.println(q);

    }
}
ods包装;
导入java.util.AbstractQueue;
导入java.util.Iterator;
导入java.util.Queue;
/**
*FIFO队列作为单链表的一种实现。
*这还包括堆栈操作push和pop,其中
*在队列的最前面操作
*@作者morin
*
*@param队列中存储的对象类
*/
公共类SLList扩展了抽象队列{
类节点{
tx;
节点下一步;
}
/**
*排在队伍前面
*/
节点头;
/**
*队伍的尾部
*/
节尾;
/**
*队列中的元素数
*/
int n;
公共迭代器迭代器(){
类SLIterator实现迭代器{
受保护节点p;
公共SLIterator(){
p=水头;
}
公共布尔hasNext(){
返回p!=null;
}
公共交通工具{
T x=p.x;
p=p.next;
返回x;
}
公共空间删除(){
抛出新的UnsupportedOperationException();
}
}
返回新的SLIterator();
}
@凌驾
公共整数大小(){
//TODO自动生成的方法存根
返回n;
}
公共布尔加法(T x){
节点u=新节点();
u、 x=x;
如果(n==0){
水头=u;
}否则{
tail.next=u;
}
尾=u;
n++;
返回true;
}
公共布尔报价(TX){
返回加(x);
}
@凌驾
公共T peek(){
返回头.x;
}
公众投票{
如果(n==0)
返回null;
T x=头部x;
head=head.next;
如果(--n==0)
tail=null;
返回x;
}
/**
*堆栈推送操作-将x推送到列表的头部
*@param x要推送到堆栈上的元素
*@return x
*/
公共T推送(T x){
节点u=新节点();
u、 x=x;
u、 下一个=头部;
水头=u;
如果(n==0)
尾=u;
n++;
返回x;
}
受保护的void deleteNext(节点u){
如果(u.next==尾部)
尾=u;
u、 next=u.next.next;
}
受保护的void addAfter(节点u、节点v){
v=u.next.next;
u、 next=v;
如果(u==尾部)
尾=v;
}
受保护节点getNode(int i){
节点u=头部;
对于(int j=0;j

任何帮助都将不胜感激!谢谢

您需要首先从包外部编译它,然后再从那里运行。e、 g

javac ods/SLList.java
然后


非常感谢。这解决了我的问题