title: Android - how to show a snackbar containing a string taken from a fragment
body: <p>I have a <code>Fragment</code> with a <code>ListView</code>. When I click on a certain element on this list I want to show the title of the clicked element inside a <code>Snackbar</code>, but I get an error. How can I solve it?</p>
  
  <p>Fragment method: <br></p>
  
  <pre><code>mListViewSongs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          View rowView = view;
          TextView tv = (TextView) rowView.findViewById(R.id.song_title);
          Song selectedSong = (Song) mListViewSongs.getItemAtPosition(position);
          String title = "▶ "+selectedSong.getSongName();
          mainActivity.setSelectedSong(title);
      }
  });
  </code></pre>
  
  <p>The method used inside the <code>Activity</code>:</p>
  
  <pre><code>public void setSelectedSong(String title) {
      Snackbar snack = Snackbar.make(coordinatorLayout, title, Snackbar.LENGTH_SHORT);
      View viewSnack = snack.getView();
      TextView txtv = (TextView) viewSnack.findViewById(android.support.design.R.id.snackbar_text);
      txtv.setGravity(Gravity.CENTER_HORIZONTAL);
      snack.show();
  }
  </code></pre>
  
  <p>Plus, I tested the Snackbar method for aligning the text in the center but it didn't work, why?</p>
  
  <p>Log:</p>
  
  <pre><code>FATAL EXCEPTION: main
  Process: com.sebbsoft.app, PID: 2080
  Theme: themes:{}
  java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.view.ViewGroup.getContext()' on a null object reference
  at android.support.design.widget.Snackbar.&lt;init&gt;(Snackbar.java:183)
  at android.support.design.widget.Snackbar.make(Snackbar.java:215)
  at com.sebbsoft.app.PlayActivity.setSelectedSong(PlayActivity.java:354)
  at com.sebbsoft.app.Fragments.TracksListFragment$2.onItemClick(TracksListFragment.java:133)
  at android.widget.AdapterView.performItemClick(AdapterView.java:310)
  at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
  at android.widget.AbsListView$PerformClick.run(AbsListView.java:3066)
  at android.widget.AbsListView$3.run(AbsListView.java:3903)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5461)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  </code></pre>