I have a very strange error that I do not understand what's going on. In my code, I use the SoundsClass through the media player like this:
public class sound class {Private audio sound; Private reference mContext; Public Voices (acute sound, context mContext) {this sound = sound; This.mContext = mContext; } Public Zero ClickOnAndroid () {Switch (This Sound) {Case R.R.O. Sound 1: Media Player Media Player = Media PlayerCreate (MCTXT, R.Ir. Sound1); MediaPlayer.start (); Mediaplayer.setOncompletionListener (new MediaPlayer.OnCompletionListener) (end to public zero (media player MP) {mp.release ();}}); break; Case R.raw.sound2: MediaPlayer = Media PlayerCreate (MCTXT, R.Ier. sound2); MediaPlayer.start (); Mediaplayer.setOncompletionListener (new MediaPlayer.OnCompletionListener) (end to public zero (media player MP) {mp.release ();}}); break; Case R.raw.sound3: mediaplayer = mediaplayer.create (mContext, R.raw.sound3); MediaPlayer.start (); Mediaplayer.setOncompletionListener (new MediaPlayer.OnCompletionListener) (end to public zero (media player MP) {mp.release ();}}); break; }} }
So, I use this class in my main activity like this:
New soundclass (R.raw .sound1, getBaseContext ()) click ononline (); This activity works fine in 2 places, but gives the third person a NullPointerException, which indicates the reason of the line in SoundsClass: mediaPlayer.start ();
Why any thoughts? Am I using MediaPlayer incorrectly?
Maybe I'm missing something obvious, so please tell it to me
Thank you!
LogKit is:
java.lang.NullPointerException.SoundsClass.ClickOn Android (soundclass.java: 42) com.testingapp on com.testingapp.app. App.MainActivity $ 2.onClick (MainActivity.java147) on android.view.View.performClick (see Java.2485) on android.view. View $ PerformClick.run (see Java: 9080) android.os.Handler.handle at Callback (Handler.Java Linux) Android.OSHandler Dispose Message (Handler. Java: 9 2) Android.OS.Lopper.Lop (Looper) Javan 30) at java.lang.reflect.Method.invoke (Method.java:507) on Com.android java.lang.reflect.Method.invoke and Native (native method) on android.app.ActivityThread.main (ActivityThread .java368) Internal.Ozagiotite at INIT $ MethodAndArgsCaller.run (ZygoteInit.java:839) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:597) at Dalvik.system.NativeStart.main (Original Method) Maybe I should add it that I The person does not stop the class very often and with or in almost any middle and sometimes I get: The buffercant is small and increases to 12.
Again, thanks!
)
Media player. This will happen when the specified media can not be found or if the media is an invalid format.
Comments
Post a Comment