java - table-layout does not compile (syntax errors) -


this question has answer here:

i have code:

public class menu  {      private skin skin;     label namelabel = new label("name:", skin);     textfield nametext = new textfield(null, skin);     label addresslabel = new label("address:", skin);     textfield addresstext = new textfield(null, skin);      table table = new table();     table.add(namelabel);     table.add(nametext).width(100);     table.row();     table.add(addresslabel);     table.add(addresstext).width(100); } 

and have problem adding:

  • syntax error on token "namelabel", variabledeclaratorid expected after token
  • syntax error on token(s), misplaced construct(s)

and

  • syntax error on token(s), misplaced construct(s)
  • syntax error on token "add", = expected after token

and

  • syntax error on token "row", identifier expected after token

and

  • syntax error on token(s), misplaced construct(s)
  • syntax error on token "addresslabel", variabledeclaratorid expected after token

and

  • syntax error on token(s), misplaced construct(s)
  • syntax error on token "add", = expected after token

i use tutorial here. doing wrong?

the problem in code writing executable statements outisde of method/constructor/block. in java cannot write executable statements directly in class. need move following statements in method:

table.add(namelabel); table.add(nametext).width(100); table.row(); table.add(addresslabel); table.add(addresstext).width(100); 

Comments