简体   繁体   中英

Java error: not a statement and I don't know why?

I'm really not sure what is causing this compile time error to occur???? I've been trying to figure it out and can't seem to find what the problem is.

ClassTable.java:253: error: not a statement
                class_c class = classes.nextElement();
                ^

ClassTable.java:253: error: ';' expected
                class_c class = classes.nextElement();
                       ^

ClassTable.java:253: error: <identifier> expected
                class_c class = classes.nextElement();
                             ^
ClassTable.java:253: error: <identifier> expected
                class_c class = classes.nextElement();
                                                   ^

ClassTable.java:254: error: illegal start of expression
                class_c parent = table.getClass(class.getParent());
                                                ^

ClassTable.java:254: error: ';' expected
                class_c parent = table.getClass(class.getParent());
                                                                 ^

ClassTable.java:264: error: illegal start of expression
        list.add(class);
                 ^

ClassTable.java:264: error: ';' expected
        list.add(class);

Here's my Code:

class ClassTable {
private int semantErrors;
private PrintStream errorStream;
private Hashtable<class_c,ArrayList<class_c>> table;
private boolean noCycles = true;

public void addClass(class_c c){
    Hashtable<class_c, ArrayList<class_c>> table = this.table();

    if(table.containsKey(c)){
        errorStream.print(c.getFilename() + ":" + c.getLineNumber() + ": " + "Class " + c.getName() + " was previously defined.");
        System.out.println();
        this.semantError();

    }
    else{
        ArrayList<class_c> list = new ArrayList<class_c>();
        table.put(c,list);
    }

}

public void addChildren(){
    Enumeration classes = this.table.keys();

    while(classes.hasMoreElements())
    {

        class_c class = classes.nextElement();
        class_c parent = table.getClass(class.getParent());


    if(!table.containsKey(parent)){
        errorStream.print(c.getFilename() + ":" + c.getLineNumber() + ": " + "Class "+ c.getName() + " inherits from an undefined class " + c.getParent()+".");
        System.out.println();
        this.semantError();
    }
    else{
    ArrayList<class_c> list = table.get(parent);
    list.add(class);
    this.table.put(parent,list);
        }
     }
   }
 }

HELP ME PLEASE. Why do I keep getting this error????

class needs to be clazz or something else. class is a reserved name in Java.

Other Java keywords are:

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

You cannot use any of the keywords as identifiers in your programs. For you information, here is a list of keywords: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

class is a reserved key word in java used to define java class.
For example:

class Test{
}

Which defines a Test class. So you should not use it to define variable or reference.
read about list of reserved words in java : http://en.wikipedia.org/wiki/List_of_Java_keywords

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM