import - Java importing Package wont work [Compiler throwing missleading Errors] -


this question has answer here:

when try import package, throws weird error. i'm working eclipse , imported package humanbeeings this:
enter image description here

the error says: syntax error, @ expected

i dont know how fix got idea?
placed @ on several places nothing seems work

the code of list collection class following:

package listcollection; import humanbeeings.human; import java.util.linkedlist; import java.util.list;      public class listcollection {         list<human> list = new linkedlist <human>(); // <> zur spezifizierung der objektklasse, nur objekte dieser klasse dürfen in die liste         list.add(new human("dennis", 20));         list.add(new human("vladimir", 33));         (human h: list) { // für das objekt der objektklasse human in der list             system.out.println(h.getname());         }     } 

the code of human class looks this..

package humanbeeings;      public class human {         // objekteigenschaften         private string name;         private int age;         // konstrucktoren         public human(string name, int age){             this.name = name;             this.age = age;         }         // accessoren/methoden         public void setname(string name){             this.name = name;         }         public string getname(){             return this.name;         }         public void setage(int age){             this.age = age;         }         public int getage(){             return this.age;         }         //main         public static void main(string[] args){             // actions here...         }     } 

the statements you've written not appear inside method. place them inside method, so:

public void testmylistcollection() {     list<human> list = new linkedlist <human>();     // etcetera } 

it important java compiler follow syntax of java closely. in particular example placed statements inside class body, not inside method body. type of statements allowed in class body "assignments", i.e. when assign value instance variable:

public class example {     private int myvalue = 3 + 3; // statement inside class body,                                  // because part of assignment } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -