title: Passing data between two Fragments in a VIewPager (Android) (NullPointerException)
body: <p>So basically I have <strong>2</strong> Fragments - <code>FragmentConverter</code> and <code>FragmentFavourites</code>, and I have one <code>MainActivity</code>. I'm trying to pass 4 arrays from the first fragment to the second one using an Interface called <code>Communicator</code>. The specific snippets are show below:</p>
  
  <pre><code>public interface Communicator {
  
      public void respond(String[] names, String[] codes, String[] symbols, int[] images);
  }
  </code></pre>
  
  <p>This is a method inside <code>FragmentFavourites</code>:</p>
  
  <pre><code>@Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // TODO Auto-generated method stub
  
          String[] checkedNames = new String[counter];
          String[] checkedCodes = new String[counter];
          String[] checkedSymbols = new String[counter];
          int[] checkedImages = new int[counter];
          comm = (Communicator) getActivity();
          int index = 0;
          if (item.getItemId() == R.id.action_save){
              for (int i=0;i&lt;checked.size();i++){
                  if (checked.get(i) == true){
                      checkedNames[index] = names[i];
                      checkedCodes[index] = codes[i];
                      checkedSymbols[index] = symbols[i];
                      checkedImages[index] = images[i];
                      index++;
                  }
  
              }
              comm.respond(checkedNames, checkedCodes, checkedSymbols, checkedImages);
          }
  
          return super.onOptionsItemSelected(item);
      }
  </code></pre>
  
  <p>This is the implemented interface method inside <code>MainActivity</code>:</p>
  
  <pre><code>@Override
  public void respond(String[] names, String[] codes, String[] symbols,
          int[] images) {
      // TODO Auto-generated method stub
      FragmentConverter frag = (FragmentConverter) fragmentPagerAdapter.getItem(1);
      frag.changeData(names, codes, symbols, images);
  }
  </code></pre>
  
  <p>And this is a method that collects the data in <code>FragmentConverter</code>:</p>
  
  <pre><code>public void changeData(String[] names, String[] codes, String[] symbols, int[] images){
          this.names = names;
          this.codes = codes;
          this.symbols = symbols;
          this.images = images;
  
          Log.d("TEST", symbols.length + names.length + codes.length + images.length + "");
          tvOneRate.setText(names[1]); 
  }
  </code></pre>
  
  <p><strong>Now the problem is that whenever I try to change a ui component inside <code>FragmentConverter</code>, I get a <code>NullPointerException</code>, though the Log.d statement returns the correct results.</strong></p>
  
  <p>EDIT1: getItem() method of FragmentPagerAdapter:</p>
  
  <pre><code>@Override
      public Fragment getItem(int i) {
          // TODO Auto-generated method stub
          Fragment frag = null;
          if (i == 0){
              frag = new FragmentFavourites();
          }
          if (i == 1){
              frag = new FragmentConverter();
          }
          return frag;
      }
  </code></pre>