title: How to handle symbol not found compile error in java?
body: <p>Is gives the error ship1 not found.
  I only declare ship1 only if condiontion is met.
  Other wise i have placed else condition which re runs the function.
  It is compilation problem, so as i was told earlier ... try catch will not work.</p>
  
  <pre><code>    public static int plantNavy(BattleBoard myBattle, int counter) {
      System.out.println("Im innnnn");
      if (counter == 0) {
          System.out.println("\nPlacing Large Ship");
      }
      else if (counter == 1) {
          System.out.println("Placing Medium Ship");
      }
      else if (counter == 2) {
          System.out.println("Placing Medium Ship");
      }
      else if (counter == 3) {
          System.out.println("Placing Small Ship");
      }
      else if (counter == 4) {
          System.out.println("Placing Small Ship");
      }
  
      System.out.println("Enter 0 to place ship horizontally");
      System.out.println("Enter 1 to place ship vertically");
  
      String align = shipAlignment.nextLine();
      if (align.length() &gt; 1) {
          System.out.println("Inappropriate value entered. Please enter again");
          plantNavy(myBattle,counter);
      }
  
      if (align.charAt(0) - 48 == 0 || align.charAt(0) - 48 == 1) {
          if (align.charAt(0) - 48 == 0) {
              if (counter == 0) {
                  BattleShip ship1 = new LargeShip(false);
              }
              else if (counter == 1) {
                  BattleShip ship1 = new MediumShip(false);
              }
              else if (counter == 2) {
                  BattleShip ship1 = new MediumShip(false);
              }
              else if (counter == 3) {
                  BattleShip ship1 = new SmallShip(false);
              }
              else if (counter == 4) {
                  BattleShip ship1 = new SmallShip(false);
              }
          }
          if (align.charAt(0) - 48 == 1) {
              if (counter == 0) {
                  BattleShip ship1 = new LargeShip(true);
              }
              else if (counter == 1) {
                  BattleShip ship1 = new MediumShip(true);
              }
              else if (counter == 2) {
                  BattleShip ship1 = new MediumShip(true);
              }
              else if (counter == 3) {
                  BattleShip ship1 = new SmallShip(true);
              }
              else if (counter == 4) {
                  BattleShip ship1 = new SmallShip(true);
              }
          }
      }
      else {
          System.out.println("Inappropriate value entered");
          counter=plantNavy(myBattle,counter);
      }
  
          System.out.println("Enter Ship Placing position");
          String shipPos = shipPlace.next();
          if (shipPos.length() &gt; 3 || shipPos.length() &lt; 2) {
              System.out.println("Inappropriate target. Please enter again");
              counter = plantNavy(myBattle,counter);
          }
          else if ((int) (shipPos.charAt(1))-48 &lt; 1 || (int)  shipPos.charAt(1)-48 &gt; 10) {
              System.out.println("Inappropriate target. Please enter again");
              counter = plantNavy(myBattle,counter);
          }
  
          else if ((int) (shipPos.charAt(0)) &lt; 65 || (int) shipPos.charAt(0)&gt; 74) {
              System.out.println("Inappropriate target. Please enter again");
              counter = plantNavy(myBattle,counter);
          }
  
          int x_pos;
          int y_pos;
  
          if (shipPos.length() == 3) {
              shipPos = shipPos.charAt(0) + "10";
          }
          if (shipPos.length() == 2) {
              x_pos = (int) (shipPos.charAt(1))-49;
          }
          else {
              x_pos = 9;
          }
          y_pos = (int) (shipPos.charAt(0))-65;
  
          System.out.println(x_pos);
          System.out.println(y_pos);
  
          boolean plantCor = myBattle.addShip(ship1,x_pos,y_pos);
  
          if (plantCor == true) {
              System.out.println(myBattle.printActualBoard());
              counter++;
              return counter;
          }
  
          if (plantCor == false) {
              System.out.println("Incorrect Placement. Place Again in empty area.");
              counter = plantNavy(myBattle,counter);
          }
      }
  </code></pre>