0

I want to create a new String[][] Array but eclipse gives me an error:

public class CurriculumVitae {

String[][] education = new String[2][6]; //throws error here and expects "{" but why?
education[0][0] = "10/2012 − heute";
education[0][1] = "Studium der Informatik";
education[0][2] = "Johannes Gutenberg−Universit \\”at Mainz";
education[0][3] = "";
education[0][4] = "";
education[0][5] = "";
education[1][0] = "10/2005 − 5/2012";
education[1][1] = "Abitur";
education[1][2] = "Muppet-Gymnasium";
education[1][3] = "Note: 1,3";
education[1][4] = "";
education[1][5] = "";}
Tak3r07
  • 547
  • 3
  • 6
  • 15

2 Answers2

2

Your declaration is ok.

However you must use an initializer block for assigning your array values.

Just enclose all education[x][y] statements within curly brackets, or move them to the constructor.

  • Initializer block example

    public class CurriculumVitae {
        String[][] education = new String[2][6];
        // initializer block
        {
            education[0][0] = "10/2012 − heute";
            education[0][1] = "Studium der Informatik";
        }
    }
    
  • Constructor example

    public class CurriculumVitae {
    
        String[][] education = new String[2][6];
        // constructor
        public CurriculumVitae()
        {
            education[0][0] = "10/2012 − heute";
            education[0][1] = "Studium der Informatik";
        }
    }
    
Mena
  • 46,817
  • 11
  • 84
  • 103
0

you code must be inside a method. For Example:

public class CurriculumVitae {

  public static void main(String[] args){
    String[][] education = new String[2][6];
    education[0][0] = "10/2012 − heute";
    education[0][1] = "Studium der Informatik";
    education[0][2] = "Johannes Gutenberg−Universit \\”at Mainz";
    education[0][3] = "";
    education[0][4] = "";
    education[0][5] = "";
    education[1][0] = "10/2005 − 5/2012";
    education[1][1] = "Abitur";
    education[1][2] = "Muppet-Gymnasium";
    education[1][3] = "Note: 1,3";
    education[1][4] = "";
    education[1][5] = "";
  }
}
Simulant
  • 18,114
  • 7
  • 59
  • 94