| Author |
Constructors and Arrays
|
Cecil Phillip
Ranch Hand
Joined: Nov 05, 2001
Posts: 40
|
|
Why does the compiler give me this error for my code Test.java [19:1] illegal start of expression tin = {1,2,3,4}; ^ 1 error Errors compiling Maya. public class Test { private int[] tin; public Test { this.tin = {1,2,3,4}; } }
|
 |
Cecil Phillip
Ranch Hand
Joined: Nov 05, 2001
Posts: 40
|
|
Correction Test.java [19:1] illegal start of expression tin = {1,2,3,4}; ^ 1 error Errors compiling Test.java public class Test { private int[] tin; public Test { this.tin = {1,2,3,4}; } }
|
 |
Nathaniel Stoddard
Ranch Hand
Joined: May 29, 2003
Posts: 1258
|
|
As far as I understand it, the {...} notation can only be used in the declaration of an array: int[] tin = {1,2,3,4}; If you later want to set tin to some other array of values, you will need to use an anonymous array: tin = new int[] {1,2,3,4};
|
Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
|
 |
Gabriel White
Ranch Hand
Joined: Mar 02, 2003
Posts: 233
|
|
Can you post your constructor? You are using the "this" command which calls one of your constructors in your class. If you define the array in your constructor, then you can call the array like you are doing. But I would just declare the entire array in the constructor or declare it in the main method. HTH
|
 |
 |
|
|
subject: Constructors and Arrays
|
|
|