以下の switch ステートメントで " } " エラーが発生するのはなぜですか。構文エラーはありません。コードのコンパイル時にエラーが発生しません。Eclipse は、以下の指定された位置でエラーを示しています。
} を入れた後、このエラーが発生します
- The static field KeyEvent.VK_XXXX should be accessed in a
static way
- case expressions must be constant expressions
switch(event.getKeyCode())
{
case event.VK_BACK_SLASH:
backColor=but[27].getBackground();
break;
case event.VK_RIGHT:
for(int i=0;i<but.length;i++)
{
if(" > ".equals(but[i].getText()))
{
backColor=but[i].getBackground();
break;
}
}
break; // error here
}
キーを押すと、次のエラーが表示されます
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "}" to complete SwitchBlock
at Keyboard$HandlerClass.keyPressed(Keyboard.java:242) // this is break statement
at java.awt.Component.processKeyEvent(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
よろしく