title: Java: Cannot find local variable (inside a method)
body: <p>I'm learning Android and Java, and got into a problem.</p>
  
  <p>i have a simple method that revrese the text i input into her:</p>
  
  <pre><code> public String ReverseIt(String strToReverse){
       String reversed = "";
      for (int i = strToReverse.length(); i &gt; 0; i--){
          reversed += strToReverse.charAt(i);
      }
      return reversed;
  };
  </code></pre>
  
  <p>I'm calling this method in a Swithc Controls event OnCheckedChangeListener:</p>
  
  <pre><code>private CompoundButton.OnCheckedChangeListener onReverseSwtichToggleChanged = new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          if(!nameEditText.getText().toString().equals("")){
              String nameInReversed = ReverseIt(nameEditText.getText().toString()) ;
              nameTextView.setText(nameInReversed);
          }
          else
              nameTextView.setText("the EditText is empty");
  
      }
  };
  </code></pre>
  
  <p>For some reason, I'm getting an Exception/Error on the reversed variable inside the method ReverseIt.</p>
  
  <p>the error is: 
  reversed = Cannot find local variable 'reversed'</p>
  
  <p>What do i do wrong?</p>