title: Android studio: Why can't I reference a variable I've declared?
body: <p>Using an Android studio empty activity (or Blank activity) if I declare an int then want to initialise it on the next line it will not let me. eg:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
       int n;
       n=1;   // generates a lint here and says unknown class 'n'
  
  }
  </code></pre>
  
  <p>It sets a lint under n=1; and tells me "unknown class: 'n' "</p>
  
  <p>...yet if I create a method I can initialise it in the method. eg: </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
       int n;
  
       public void test() {
            n=1;
       }
  
  }
  </code></pre>
  
  <p>It will also allow me to declare an int THEN initialise it on the next line INSIDE the method. eg:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
       public void test() {
            int n;
            n=1;
       }
  
  }
  </code></pre>
  
  <p>Could someone please explain why I cannot reference a variable I have set inside the MainActivity class? Thank you.</p>