title: Android: Help! Application has stopped working
body: <p>I am trying to make an app on which i can read poems that ive stored through Array .
  It contains 2 buttons "Next" &amp; "Back" </p>
  
  <p>Everything seems to work fine but when i reach the end of array and i press next it stops working. and vice versa for back key.</p>
  
  <pre><code>    package com.example.haziqsheikhlocal.ghanwapoems;
  
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.view.View;
  import android.widget.Button;
  import android.widget.Switch;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import java.util.Random;
  
  
  public class GhanwaPoems extends ActionBarActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_ghanwa_poems);
  
          final TextView myPoem1 = (TextView) findViewById(R.id.myPoem);
           final Button nextButton = (Button) findViewById(R.id.buttonNext);
          final Button backButton = (Button) findViewById(R.id.backButton);
  
  
  
          View.OnClickListener backListen = new View.OnClickListener() {
              public int kK =0;
              @Override
              public void onClick(View v) {
                  String[] mPoemBooks = getStrings();
  
  
                  if (kK &lt;= mPoemBooks.length - 1 || kK &gt;= 1 ){
                      switch (v.getId())   // v is the button that was clicked
                      {
                          case(R.id.buttonNext):
                              kK++;
                              break;
                          case (R.id.backButton):
                              kK--;
                              break;
                          default:   // this will run the same code for any button clicked that doesn't have id of button1 defined in xml
  
                              break;
  
                      }
                      int k = kK;
                      String myPoem = "";
                      myPoem = mPoemBooks[k];
  
  
  
                      myPoem1.setText(myPoem);
                  }
  else {
                      Toast.makeText(getApplicationContext(), " Sorry No More To Show" , Toast.LENGTH_LONG).show();
                  }
  
              }
  };
                         backButton.setOnClickListener(backListen);
                         nextButton.setOnClickListener(backListen);
  
      }
  
      private String[] getStrings() {
          return new String[]{"","a","b","c","d","e","f"};
      }
  }
  </code></pre>
  
  <p>What i need is a logic or condition so that when i reach to the end of my array it should display "Sorry No More Poems." and vice versa for back button. </p>
  
  <p>and sorry for the messed code its first time i am making something :P </p>