title: Android ImageButton Onclick not working
body: <p>I'm trying to change images when an image button is clicked. Even without the code for changing image my application is crashing whenever I use an onClickListener or try to set an onClick listener. How do i fix this I'm running app on kitkat api 19</p>
  
  <pre><code>package com.example.t11;
  
  import android.R.string;
  import android.support.v7.app.ActionBarActivity;
  import android.content.Intent;
  
  
  
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.ImageButton;
  import android.widget.ImageView;
  
  public class Scene extends ActionBarActivity {
  
  ImageView scene=(ImageView) findViewById(R.id.images);
  
  int i=0;
  
  int[] imgarray =    {R.drawable.i1,R.drawable.i2,R.drawable.i4,R.drawable.i6,R.drawable.i7,R.drawable.i8,R.drawable.i9,R.drawable.i10,R.drawable.i12};
  
   //Just set one Click listener for the image
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_scene);
      Intent sceneint = getIntent();
  
      ImageButton left = (ImageButton) findViewById(R.id.left);
      ImageButton right= (ImageButton) findViewById(R.id.right);
  
      // Left and right button listener creation
      left.setOnClickListener(leftlistener);
      right.setOnClickListener(rightlistener);
  
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.scene, menu);
      return true;
  }
  
  
  View.OnClickListener rightlistener = new OnClickListener() {
  
  
      public void onClick(View v1) {
          //Increase Counter to move to next Image
      i++;
  
  
      scene.setImageResource(imgarray[i]);
      }
  };
  
   View.OnClickListener leftlistener = new OnClickListener() {
  
       public void onClick(View v) {
          //Increase Counter to move to Previous Image
          i--;
  
  
          scene.setImageResource(imgarray[i]);
          }
      };
  
  
  
  
  
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  }
  </code></pre>