简体   繁体   English

枚举无法用Java解析

[英]enum cannot be resolved in Java

I 'm havin a problem with resolving enum. 我解决了枚举问题。

I checked previous answers like why enum could not be resolved in JAVA? 我检查过以前的答案, 为什么无法在JAVA中解析枚举?

and I did the answer but I still get the error. 我做了答案,但我仍然得到错误。 also followed another solution to change the compiler compliance level. 还遵循另一个解决方案来更改编译器合规性级别。 but in my case it is originally set to 1.6 但在我的情况下,它最初设置为1.6

what should be changed here ? 应该在这里改变什么?

Code : 代码:

CellTypes.java CellTypes.java

public enum CellTypes {
  STRING,LIST,PATH
}

in the event of canModify which is overriden 如果canModify被覆盖

desc : desc:

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

just calling setEditor method and setEditor is as follows 只是调用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();
  }

} }

causes an error of cannot resolve CellTypes type where ct is recognised as enum and its type is STRING 导致错误无法解析其中ct被识别为枚举且其类型为STRING的CellTypes类型

Change 更改

if (ct = CellTypes.STRING)

to

if (ct == CellTypes.STRING)

You are assigning iso. 你正在分配iso。 comparing. 比较。

If I understood you correctly, you are comparing the String name of the enum value to an enum value. 如果我理解正确,您将枚举值的String名称与枚举值进行比较。 Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM