MediaPlayer is not running the previous sound in android either after released the object and initialized its again
<p>There are two onClickListener one for move forward and the second one is to move backward. I have an array of images, sounds and texts. by pressing forward it moves to the next record and with backward it moves to previous. I faced an issue that if a sound played for a single time at any position. when i tried to move on it by pressing backward then the sound isn't plays. it only plays for a single time if i want to plays it more than one time it isn't plays and break and generates an exception of null pointer to global_media_player. Here global_media_player is the global object.</p>

<pre><code>forward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (count &gt;= 0 &amp;&amp; count &lt; (list.size() - 1)) {
                    count++;
                    Toast.makeText(getApplicationContext(),"Before Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
//                    if(global_media_player.isPlaying()) {
//                        global_media_player.stop();
//                        Toast.makeText(getApplicationContext(),"During Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
//                    }

                    BookData data = list.get(count);
                    textView.setText(data.getName());
                    imageView.setImageDrawable(data.getImage());
                    Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);
                    textView.startAnimation(slide);
                    try {
                        Toast.makeText(getApplicationContext(),"Before Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        if (global_media_player != null) {
                            global_media_player.release();
                            Toast.makeText(getApplicationContext(),"During Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        }
                        Toast.makeText(getApplicationContext(),"Before Initialing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        global_media_player = data.getAudio();
                        Toast.makeText(getApplicationContext(),"Before Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        global_media_player.start();
                        Toast.makeText(getApplicationContext(),"After Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();


                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }


            }
        });
        backward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (count &gt; 0 &amp;&amp; count &lt; list.size()) {
                    count--;
                    Toast.makeText(getApplicationContext(),"Before Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
//                    if(global_media_player.isPlaying()) {
//                        global_media_player.stop();
//                        Toast.makeText(getApplicationContext(),"During Stop "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
//                    }


                    BookData data = list.get(count);
                    textView.setText(data.getName());
                    imageView.setImageDrawable(data.getImage());
                    Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide);
                    textView.startAnimation(slide);
                    try {
                        Toast.makeText(getApplicationContext(),"Before Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        if (global_media_player != null) {
                            global_media_player.release();
                            global_media_player = null;
                            Toast.makeText(getApplicationContext(),"During Releasing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        }
                        Toast.makeText(getApplicationContext(),"Before Initialing "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        global_media_player = data.getAudio();
                        Toast.makeText(getApplicationContext(),"Before Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                        global_media_player.start();
                        Toast.makeText(getApplicationContext(),"After Start "+global_media_player.toString(),Toast.LENGTH_SHORT).show();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            }
        });
</code></pre>