title: next / prevous button slide image
body: <p>i am getting error on previous button when i want to show image1 to image6 it show me the error <strong>ArrayIndexOutOfBoundsException: length=6; index=-1</strong>
  how to set when previous button come to image1 to not try to show image 6 to do nothing?</p>
  
  <p>here is my code    </p>
  
  <pre><code>public class MainActivity extends Activity {
  Intent i;
  private int mNekiPhotoIndex =0;
  private int[] mSlikeID = new int[] { R.drawable.pic,
          R.drawable.pic1, R.drawable.pic2, R.drawable.pic3,
          R.drawable.pic4, R.drawable.ic_launcher, };
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
       showPhoto(mNekiPhotoIndex);
  
  
  
      // 'Next' button.
          Button nextButton = (Button) findViewById(R.id.next_button);
          nextButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
  
                  mNekiPhotoIndex = (mNekiPhotoIndex + 1)
                          % mSlikeID.length;
                  showPhoto(mNekiPhotoIndex);
              }
          });
       //  'Prev' button.
          Button prevButton = (Button) findViewById(R.id.prev_button);
          prevButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  mNekiPhotoIndex = (mNekiPhotoIndex - 1)
                          % mSlikeID.length;
                  showPhoto(mNekiPhotoIndex);
              }
          });
  
  }
  @Override
  protected void onSaveInstanceState(Bundle outState) {
      outState.putInt("photo_index", mNekiPhotoIndex);
      super.onSaveInstanceState(outState);
  }
  @Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
      mNekiPhotoIndex = savedInstanceState.getInt("photo_index");
      showPhoto(mNekiPhotoIndex);
      super.onRestoreInstanceState(savedInstanceState);
  }
  
  private void showPhoto(int PhotoIndex) {
  
      // TODO Auto-generated method stub
      ImageView imageView = (ImageView) findViewById(R.id.image_view);
      imageView.setImageResource(mSlikeID[PhotoIndex]);
  }
  </code></pre>
  
  <p>}</p>