为什么下面的程序说我"keysTocutBysections = {{}}"非法表达式开始?
public class GetAllContent {
    String address;
    String[][] keysTocutBysections;
    public String GetAllCont (String addr, String keyword) {
        address = addr;
        if (address.indexOf("9") != -1) {
            keysTocutBysections = {{}};
        }
        return "0";
    }
    public static void main(String[] args) {
        GetAllContent xx = new GetAllContent();
        xx.GetAllCont("99", "0");
        
    }
}

解决方案 »

  1.   

    没有初始化啊
    -------------
    我已经在String[][] keysTocutBysections;说明变量了,即使用keysTocutBysections = {{“55", "44"}};初始化也一样。
      

  2.   

    哦 不好意思 刚才没细心看 这个应该是数组静态初始化的时候 应该在声明数组的时候同时进行初始化
    String address;
       public String GetAllCont (String addr, String keyword) {
      address = addr;
      if (address.indexOf("9") != -1) {
      String[][]  keysTocutBysections = {{}};
      }
      return "0";
      }
      public static void main(String[] args) {
      GetAllContent xx = new GetAllContent();
      xx.GetAllCont("99", "0");
        
      }这样应该不会有问题,或者可以用new动态分配
    String address;
    String[][] keysTocutBysections=null;
      public  String GetAllCont (String addr, String keyword) {
      address = addr;
      if (address.indexOf("9") != -1) {
     keysTocutBysections = new String[][]{{}};
      }
      return "0";
      }
      public static void main(String[] args) {
      GetAllContent xx = new GetAllContent();
      xx.GetAllCont("99", "0");
        
      }
    至于原理我也不是很懂 等高人解答