Hi,I encountered some problems when i am learning the treeSet. The following is the code. Could anyone help me please? The error messages are "TreetSet cannot be resolved or is not a type". I couldn't tell the problems. Thank you.
======================================
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;public class Demo {
public static void main(String[] args){
HashMap hashMap=new HashMap();

hashMap.put("Schmidt","+49 6227 48597");
hashMap.put("Mayer","+49 6221 1808");
hashMap.put("Schmidt","+49 40 364850");
hashMap.put("Treusch","+49 89 98965456");

Set keys= hashMap.keySet();
Iterator iter=keys.iterator();

while (iter.hasNext()){
String key=(String) iter.next();
String value=(String) hashMap.get(key);
System.out.println("key: "+key+"\tvalue: "+value);
}

TreetSet treetSet=new TreetSet();

treetSet.add(new Customer("Schmidt",48597));
treetSet.add(new Customer("Mayer",180));
treetSet.add(new Customer("Schmidt",3648));

Iterator iter2=treetSet.iterator();
while (iter2.hasNext()){
Customer customer=(Customer)iter2.next();
System.out.println(customer.getName());
}
}

public class Customer implements Comparable{
private String name;
private int id;

public Customer(String name, int id){
this.name=name;
this.id=id;
}

public int getId(){
return id;
}

public String getName(){
return name;
}

public int compareTo(Object otherCustomer){
return this.id=((Customer)otherCustomer).getId();
}
}
}

解决方案 »

  1.   

    "TreetSet cannot be resolved or is not a type". 这么明显的事情 是你拼错了 应该是TreeSet
      

  2.   

    ..................
    我发觉了一个问题,好多人还在用手写JAVA代码,没有用过IDE
      

  3.   

    Sorry for the silly mistakes. I have been practicing the java by not using the IDE tools to gain a better understanding of this language. I have fixed the errors but still have some errors needed to be fixed.========================================
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.TreeSet;public class Demo {
    public static void main(String[] args){
    HashMap hashMap=new HashMap();

    hashMap.put("Schmidt","+49 6227 48597");
    hashMap.put("Mayer","+49 6221 1808");
    hashMap.put("Schmidt","+49 40 364850");
    hashMap.put("Treusch","+49 89 98965456");

    Set keys= hashMap.keySet();
    Iterator iter=keys.iterator();

    while (iter.hasNext()){
    String key=(String) iter.next();
    String value=(String) hashMap.get(key);
    System.out.println("key: "+key+"\tvalue: "+value);
    }

    TreeSet treeSet=new TreeSet();

    treeSet.add(new Customer("Schmidt",48597));
    treeSet.add(new Customer("Mayer",180));
    treeSet.add(new Customer("Schmidt",3648));

    Iterator iter2=treeSet.iterator();
    while (iter2.hasNext()){
    Customer customer=(Customer)iter2.next();
    System.out.println(customer.getName());
    }
    }

    public class Customer implements Comparable{
    private String name;
    private int id;

    public Customer(String name, int id){
    this.name=name;
    this.id=id;
    }

    public int getId(){
    return id;
    }

    public String getName(){
    return name;
    }

    public int compareTo(Object otherCustomer){
    return this.id=((Customer)otherCustomer).getId();
    }
    }
    }The error message is "No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where x is an instance of Demo)."
      

  4.   

    import java.util.HashMap; 
    import java.util.Iterator; 
    import java.util.Set; 
    import java.util.TreeSet; public class Demo { 
    public static void main(String[] args){ 
    HashMap hashMap=new HashMap(); hashMap.put("Schmidt","+49 6227 48597"); 
    hashMap.put("Mayer","+49 6221 1808"); 
    hashMap.put("Schmidt","+49 40 364850"); 
    hashMap.put("Treusch","+49 89 98965456"); Set keys= hashMap.keySet(); 
    Iterator iter=keys.iterator(); while (iter.hasNext()){ 
    String key=(String) iter.next(); 
    String value=(String) hashMap.get(key); 
    System.out.println("key: "+key+"\tvalue: "+value); 
    } TreeSet treeSet=new TreeSet(); treeSet.add(new Customer("Schmidt",48597)); 
    treeSet.add(new Customer("Mayer",180)); 
    treeSet.add(new Customer("Schmidt",3648)); Iterator iter2=treeSet.iterator(); 
    while (iter2.hasNext()){ 
    Customer customer=(Customer)iter2.next(); 
    System.out.println(customer.getName()); 


    } class Customer implements Comparable{ 
    private String name; 
    private int id;  public Customer(String name, int id){ 
    this.name=name; 
    this.id=id; 
    }  public int getId(){ 
    return id; 
    }  public String getName(){ 
    return name; 
    }  public int compareTo(Object otherCustomer){ 
    return this.id=((Customer)otherCustomer).getId(); 

      

  5.   

    或者这样晦涩点
    import java.util.HashMap; 
    import java.util.Iterator; 
    import java.util.Set; 
    import java.util.TreeSet; public class Demo { 
    public static void main(String[] args){ 
    HashMap hashMap=new HashMap(); hashMap.put("Schmidt","+49 6227 48597"); 
    hashMap.put("Mayer","+49 6221 1808"); 
    hashMap.put("Schmidt","+49 40 364850"); 
    hashMap.put("Treusch","+49 89 98965456"); Set keys= hashMap.keySet(); 
    Iterator iter=keys.iterator(); while (iter.hasNext()){ 
    String key=(String) iter.next(); 
    String value=(String) hashMap.get(key); 
    System.out.println("key: "+key+"\tvalue: "+value); 
    } TreeSet treeSet=new TreeSet(); treeSet.add(new Demo().new Customer("Schmidt",48597)); 
    treeSet.add(new Demo().new Customer("Mayer",180)); 
    treeSet.add(new Demo().new Customer("Schmidt",3648)); Iterator iter2=treeSet.iterator(); 
    while (iter2.hasNext()){ 
    Customer customer=(Customer)iter2.next(); 
    System.out.println(customer.getName()); 

    } class Customer implements Comparable{ 
    private String name; 
    private int id; public Customer(String name, int id){ 
    this.name=name; 
    this.id=id; 
    } public int getId(){ 
    return id; 
    } public String getName(){ 
    return name; 
    } public int compareTo(Object otherCustomer){ 
    return this.id=((Customer)otherCustomer).getId(); 


      

  6.   

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package exp1;/**
     *
     * @author 波
     */
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.TreeSet;public class Demo {    public static void main(String[] args) {
            HashMap hashMap = new HashMap();        hashMap.put("Schmidt", "+49 6227 48597");
            hashMap.put("Mayer", "+49 6221 1808");
            hashMap.put("Schmidt", "+49 40 364850");
            hashMap.put("Treusch", "+49 89 98965456");        Set keys = hashMap.keySet();
            Iterator iter = keys.iterator();        while (iter.hasNext()) {
                String key = (String) iter.next();
                String value = (String) hashMap.get(key);
                System.out.println("key: " + key + "\tvalue: " + value);
            }        TreeSet tree = new TreeSet();        tree.add(new Demo().new Customer("Schmidt", 48597));
            tree.add(new Demo().new Customer("Mayer", 180));
            tree.add(new Demo().new Customer("Schmidt", 3648));        Iterator iter2 = tree.iterator();
            while (iter2.hasNext()) {
                Customer customer = (Customer) iter2.next();
                System.out.println(customer.getName());
            }
        }    public class Customer implements Comparable {        private String name;
            private int id;        public Customer(String name, int id) {
                this.name = name;
                this.id = id;
            }        public int getId() {
                return id;
            }        public String getName() {
                return name;
            }        public int compareTo(Object otherCustomer) {
                return this.id = ((Customer) otherCustomer).getId();
            }
        }
    }
      

  7.   

    netbeans测试通过, tree.add(new Demo().new Customer("Schmidt", 48597));
    这个的参数传递的也不对