Android: using mediaplayer inside recyclerview
<p>I want to use mediaplayer in each item of my recycler view. I want to play audio immediately on a particular item when its shown.</p>

<p>I am trying:</p>

<pre><code>public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, final int i) {
vhplaymusic = (PersonViewHolderplaymusic) viewHolder;
mp = MediaPlayer.create(viewHolder.itemView.getContext(), Uri.parse(context.getExternalFilesDir("krishna").getPath() + "/amalharinaam_finalcut_loud.mp3"));
mp.start();
}
</code></pre>

<p>when in try to run, It says mp is null.</p>

<p>logcat for the error:</p>

<pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Process: com.simha.sacredindaapp, PID: 29281
E/AndroidRuntime: java.lang.NullPointerException
E/AndroidRuntime:     at com.simha.yatras.Myplanshowrvadapter.onBindViewHolder(Myplanshowrvadapter.java:410)
E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5217)
E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5250)
E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4487)
E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
</code></pre>