枚举无法用Java解析

时间:2014-01-20 10:41:15

标签: java eclipse enums

我解决了枚举问题。

我查看了之前的答案,例如why enum could not be resolved in JAVA?

我做了答案,但我仍然得到了错误。还遵循另一个解决方案来更改编译器合规性级别。但在我的情况下,它最初设置为1.6

这里应该改变什么?

代码:

CellTypes.java

public enum CellTypes {
  STRING,LIST,PATH
}

如果canModify被覆盖

desc:

/ **     * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object,     * java.lang.String)     * /

只需调用setEditor方法和setEditor如下

 public void setEditor(int editorIndex, List<Object> choices, CellTypes UIType) {
    try {
     if (choices != null) {
       String[] choicesArray = new String[choices.size()];
       for (int i = 0; i < choices.size(); i++) {
          choicesArray[i] = choices.get(i).toString();

     }
     editors[editorIndex] = new ComboBoxCellEditor(table, choicesArray, SWT.READ_ONLY);
     editors[editorIndex].getControl().addTraverseListener(traverseListener);
     columnEditorTypes[editorIndex] = EditorTypes.COMBO;

  } else if(UIType == CellTypes.PATH) {      // it gives "cannot resolve type " here
     editors[editorIndex] = standardEditors.get(EditorTypes.PATH);
     columnEditorTypes[editorIndex] = EditorTypes.PATH;
  }
  else 
  {
     editors[editorIndex] = standardEditors.get(EditorTypes.STRING);
     columnEditorTypes[editorIndex] = EditorTypes.STRING;
  }}
  catch(Exception e)
  {
     e.printStackTrace();
  }

}

导致错误无法解析CellTypes类型 其中ct被识别为枚举,其类型为STRING

2 个答案:

答案 0 :(得分:1)

更改

if (ct = CellTypes.STRING)

if (ct == CellTypes.STRING)

你正在分配iso。比较

答案 1 :(得分:1)

如果我理解正确,您将枚举值的String名称与枚举值进行比较。试试这个:

if (CellTypes.valueOf(ct) == CellTypes.STRING)