0

「世界は最終的に宣言されなければならない」というこのエラーを理解できないようです。何かアドバイス?gridworld プロジェクト(マッチングゲーム)を作っています。セグメント

  temparray.add(world.getLocation().getColor() );

final である必要があります...しかし、 final world.get などを追加すると、不正な式の開始が示されます。

import info.gridworld.actor.ActorWorld;
import info.gridworld.actor.*;
import info.gridworld.grid.*;
import info.gridworld.world.*;



import java.awt.Color;
import java.util.ArrayList;

public class cardGameDriver extends ActorWorld
   {
   public static void main( String[] args )
  {
  World world = new World();
  world.show();

  world.add( new card1());
  world.add( new card1()); 
  world.add( new card2()); 
  world.add( new card2());
  world.add( new card3());
  world.add( new card3());
  world.add( new card4());
  world.add( new card4());
  world.add( new card5());
  world.add( new card5());
  world.add( new card6());
  world.add( new card6());
  world.add( new card7());
  world.add( new card7());
  world.add( new card8());
  world.add( new card8());
  world.add( new card9());
  world.add( new card9());
  world.add( new card10());
  world.add( new card10());
  world.add( new card11());
  world.add( new card11());
  world.add( new card12());
  world.add( new card12());
  world.add( new card13());
  world.add( new card13());
  world.add( new card14());
  world.add( new card14());
  world.add( new card15());
  world.add( new card15());
  world.add( new card16());
  world.add( new card16());
  world.add( new card17());
  world.add( new card17());
  world.add( new card18());
  world.add( new card18());
  System.out.println( "Time yourself to see how fast you can make all 18 matches." );


  ArrayList<cards> temparray = new ArrayList<cards>();


  java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager() 
  .addKeyEventDispatcher(new java.awt.KeyEventDispatcher() 
  {
  public boolean dispatchKeyEvent(java.awt.event.KeyEvent event) 
     { 
     String key = javax.swing.KeyStroke.getKeyStrokeForEvent(event).toString(); 
     int x = 0;
     if (key.equals("pressed ENTER")) 
        {
        temparray.add(world.getLocation().getColor() );
        x++;
        if( x == 2 )
           {
           if( temparray.get(0) == temparray.get(1) )
              {
              System.out.println( "User has made a match!" );
              }
           else
              {
              System.out.println( "Try again!" );
              }
           x = 0;
           }
        }
     return true; 
       } 
  }); 

  }

}

4

2 に答える 2

5

メソッドのローカル クラス内でローカル変数を使用しようとしているため、変数を宣言する必要がありますfinalfinalしたがって、変数宣言に修飾子を追加するだけです。

final World world = new World();

mainローカルクラスではなく、メソッドに対してローカルである他の変数についても同様ですtemparray

于 2014-03-04T22:38:56.580 に答える