以下写法,那里出错了。
  那个part类。该如何声明? public static Vector Creattest(Vector db) {        class part {
            public ArrayList nodeitem;
            public int size;
            public int status;
            public int deep;
            public int dbid;
            public part(ArrayList nodeitem, int deep, int dbid) {
                if (nodeitem == null) {
                    this.status = 0;
                    this.size = 0;
                    this.deep = deep;
                    this.dbid = dbid;
                    return;
                }
                //this.nodeitem= nodeitem;
                this.status = 0;
                this.deep = deep;
                this.dbid = dbid;
                //this.size = nodeitem.size();
            }            public part() {
                this.status = 0;
                this.size = 0;
                this.deep = 0;
                this.dbid = -1;
            }            public int pop() {
                return (int)this.nodeitem.indexOf(this.status);
            }            public boolean HasNext() {
                return this.status < this.size;
            }
        }
        Stack stack = new Stack();
        Vector Tree = new Vector();
        HashMap hashmap = new HashMap<String, ArrayList>((int) (db.size()));        int itemnum = db.size();
        //System.out.println(db.size()+";"+db);
        int rootid = -1;
        Tree.add(itemnum / 3);
        part root = new part();   // 一运行,初始化出错。??
       /* for (int i = 0; i < itemnum; i += 3) {
            if (db.elementAt(i) == null) {
                rootid = i;
                db.setElementAt("", i);
            }
            ArrayList list = (ArrayList) hashmap.get(db.elementAt(i));
            System.out.println(list);
            if (list == null) {
                list = new ArrayList();
            }
            list.add(i + 1);
            hashmap.put(db.elementAt(i), list);
        }
        System.out.println("hear!");
        System.out.println((ArrayList) hashmap.get(""));
        System.out.println("hear!");*/
        
        /*
        System.out.println("hear!");
        stack.add(root);
        while (false == stack.isEmpty()) {
            part node = (part) stack.peek();
            Tree.addElement(db.elementAt(node.dbid));
            Tree.addElement(draw(node.deep) +
                            (String) db.elementAt(node.dbid + 1));
            if (node.HasNext()) {
                String tmp = (String) db.elementAt(node.pop());
                if (hashmap.containsKey(tmp)) {
                    stack.add(new part((ArrayList) hashmap.get(tmp),
                                       node.deep + 1, node.status - 1));
                }
            } else {
                stack.pop();
            }
        }
        for (int i = 0; i < Tree.size(); i++) {
            System.out.println(Tree.elementAt(i));
        }*/
        return Tree;
    }

解决方案 »

  1.   

    这个只是调用它就可以了(由于代码很长所以,未全部贴上)。 
    public static Vector Creattest(Vector db) 是CreatTree 类中的一个方法。
    而我想,在Vector 中自定义一个类,作为方法Vector中的堆栈stack 的一种数据类型。
    但是,程序一运行到这里:
     part root = new part();   
    就开始报错。
    我初学JAVA对,JAVA里面的类定义,有些不太熟悉。 望指教。
      

  2.   

    你的这个class part 定义能不能放在类一级的地方,不要将其放在一个方法中定义?
      

  3.   

    class中能包含class , 但方法不能包含class