title: Trying to categorize
body: <p>So I am building an application about facts. I have created different buttons for different activities where I have my facts presented in textview. I have created different text files in assets from where the facts are picked. The problem is that everytime I tap on the button my application crashes. Help me guys...</p>
  
  <p>My xml code </p>
  
  <pre><code>&lt;TextView android:text="@string/hello_world" android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerVertical="true"
      android:id="@+id/n"
      android:layout_centerHorizontal="true"
      android:textSize="35dp" /&gt;
  &lt;ImageButton
      android:layout_width="80dp"
      android:layout_height="80dp"
      android:id="@+id/btn"
      android:background="@drawable/boombuttonnext"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:layout_alignParentEnd="true" /&gt;
  
  &lt;ImageButton
      android:layout_width="80dp"
      android:layout_height="80dp"
      android:id="@+id/prev"
      android:background="@drawable/backk"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>My Java code</p>
  
  <pre><code>public class MainActivity22Activity extends AppCompatActivity {
  
      ImageButton btn,prev;
      TextView tc;
      ArrayList&lt;String&gt; listOfFacts;
      int position = 0;
  
      void init()
      {
          listOfFacts = new ArrayList&lt;String&gt;();
  
          try {
              InputStream is =  getAssets().open("boom.txt");
  
              BufferedReader in = new BufferedReader(new InputStreamReader(is));
              String line ;
              while( (line =  in.readLine())   != null)
                  listOfFacts.add(line);
  
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
  
          setContentView(R.layout.activity_main);
          init();
  
  
  
  
          position =   getSharedPreferences("storage" ,1).getInt("pos",0);
  
  
          btn  = (ImageButton) findViewById(R.id.btn);
          prev  = (ImageButton) findViewById(R.id.prev);
          tc = (TextView) findViewById(R.id.b);
  
          tc.setText("" + listOfFacts.get(position));
  
  
  
  
  
          btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
  
  
                  position++;
  
                  if(listOfFacts.size()==position)
                      position = 0;
  
                  tc.setText("" + listOfFacts.get(position));
  
  
              }
          });
  
          prev.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  position--;
  
                  if(position&lt;0)
                      position = listOfFacts.size()-1;
  
                  tc.setText("" + listOfFacts.get(position));
  
              }
          });
  
      }
  
  
      @Override
      protected void onPause() {
          super.onPause();
          getSharedPreferences("storage" ,1).edit().putInt("pos" , position).commit();
      }
  }
  </code></pre>