如何初始化多维数组?

时间:2019-05-24 21:25:10

标签: java

真的很抱歉问这个愚蠢的问题,但是我很沮丧。我基本上是C / C ++开发人员,但我不明白自己在做什么错。每个初始化行“ transition”都标记为错误。当我删除所有行时,没有值的数组不会出现错误。我看过Java教程和几篇2D帖子,看来我做得正确。我在做什么错了?

**Java**
enum FSM_STATES         {                 // FSM State names
                          TEXT_ONLY       //!< Text only GUI
                        , CHOOSER         //!< Text and File Chooser GUI
                        , DIALOG          //!< Text and Dialog GUI
                        , ALL             //!< Text, File Chooser and Dialog GUI
                        }; // enum STATES

    static FSM_STATES[][] transition = {
/*
 *                               Mealy Machine transition table
 *                      |                     states                    |
 *                      |-----------+-----------+-----------+-----------|
 *        events        | TEXT_ONLY | CHOOSER   | DIALOG    | ALL       |
 *                      |-----------+-----------+-----------+-----------| */
 /* CHOOSER_EVENT      */{ CHOOSER,   CHOOSER,    ALL,        ALL       }
 /* DIALOG_EVENT       */{ DIALOG,    ALL,        DIALOG,     ALL       }
 /* END_CHOOSER_EVENT  */{ TEXT_ONLY, TEXT_ONLY,  DIALOG,     DIALOG    }
 /* END_DIALOG_EVENT   */{ TEXT_ONLY, CHOOSER,    TEXT_ONLY,  TEXT_ONLY }
 /* RESET_EVENT        */{ TEXT_ONLY, TEXT_ONLY,  TEXT_ONLY,  TEXT_ONLY }
 }; // FSM_STATES transition[][]

1 个答案:

答案 0 :(得分:2)

您需要在值之前加上FSM_STATES.,以显示值所属的枚举。另外,您还需要在2D数组中的每个“行” / 1D数组之间添加逗号。

static FSM_STATES[][] transition = {
            /*
             *                               Mealy Machine transition table
             *                      |                     states                    |
             *                      |-----------+-----------+-----------+-----------|
             *        events        | TEXT_ONLY | CHOOSER   | DIALOG    | ALL       |
             *                      |-----------+-----------+-----------+-----------| */
            /* CHOOSER_EVENT      */{ FSM_STATES.CHOOSER,   FSM_STATES.CHOOSER,    FSM_STATES.ALL,        FSM_STATES.ALL       },
            /* DIALOG_EVENT       */{ FSM_STATES.DIALOG,    FSM_STATES.ALL,        FSM_STATES.DIALOG,     FSM_STATES.ALL       },
            /* END_CHOOSER_EVENT  */{ FSM_STATES.TEXT_ONLY, FSM_STATES.TEXT_ONLY,  FSM_STATES.DIALOG,     FSM_STATES.DIALOG    },
            /* END_DIALOG_EVENT   */{ FSM_STATES.TEXT_ONLY, FSM_STATES.CHOOSER,    FSM_STATES.TEXT_ONLY,  FSM_STATES.TEXT_ONLY },
            /* RESET_EVENT        */{ FSM_STATES.TEXT_ONLY, FSM_STATES.TEXT_ONLY,  FSM_STATES.TEXT_ONLY,  FSM_STATES.TEXT_ONLY }
    }; // FSM_STATES transition[][]