title: android studio, button object not recognized,
body: <p>After importing View, and Button.
  I have created an object for Button, in this case "thomasButton".</p>
  
  <p>But error stated the field 'thomasButton" is not used even though I have called it at the next line. </p>
  
  <p>After awhile, I found that the field can be recognized if I put it in another scope. like this, but still the program wont run (crash when started). Do you guys know what is the correct way to setOnLongClickListener for a button?</p>
  
  <pre><code>package com.example.thoma.event;
  
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  public void displayMessage(View v){
      TextView thomasText = (TextView)findViewById(R.id.txt_View);
      thomasText.setText(R.string.rsc_Text2);x
  }
  
  Button thomasButton = (Button)findViewById(R.id.btn_Change);
  // weird but I can only use Button object within an inner scope
  {
      thomasButton.setOnLongClickListener(new View.OnLongClickListener() {
          public boolean onLongClick(View v) {
              TextView thomasText = (TextView) findViewById(R.id.txt_View);
              thomasText.setText("Artificial");
              // it will return false if long click wasnt long enough
              // and normal click will be called
              return true;
          }
      });
  }
  }
  </code></pre>
  
  <p>Crash: Unfortunately, App has stopped</p>