MP3声音持续时间0秒没有在android中播放,日志nullpointerexception错误

时间:2014-03-31 15:27:51

标签: android android-mediaplayer android-audiomanager

此处click21是持续0秒的mp3声音,我从click21.aiff转换。但是当我运行它时,我收到nullpointexception类型的错误错误 你能告诉我什么是问题吗?

 MediaPlayer mp;
 mp =MediaPlayer.create(this, R.drawable.click21);
    mp.start();

错误日志

03-31 11:39:56.371: E/AndroidRuntime(811): FATAL EXCEPTION: main
03-31 11:39:56.371: E/AndroidRuntime(811): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.simba.silicon/com.simba.silicon.startscreen.CircleMenuScreen}: java.lang.NullPointerException
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.os.Looper.loop(Looper.java:137)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.ActivityThread.main(ActivityThread.java:5103)
03-31 11:39:56.371: E/AndroidRuntime(811):  at java.lang.reflect.Method.invokeNative(Native Method)
03-31 11:39:56.371: E/AndroidRuntime(811):  at java.lang.reflect.Method.invoke(Method.java:525)
03-31 11:39:56.371: E/AndroidRuntime(811):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
03-31 11:39:56.371: E/AndroidRuntime(811):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-31 11:39:56.371: E/AndroidRuntime(811):  at dalvik.system.NativeStart.main(Native Method)
03-31 11:39:56.371: E/AndroidRuntime(811): Caused by: java.lang.NullPointerException
03-31 11:39:56.371: E/AndroidRuntime(811):  at com.zippy.zippyapp.startscreen.CircleMenuScreen.onCreate(CircleMenuScreen.java:127)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.Activity.performCreate(Activity.java:5133)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-31 11:39:56.371: E/AndroidRuntime(811):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
03-31 11:39:56.371: E/AndroidRuntime(811):  ... 11 more

1 个答案:

答案 0 :(得分:0)

当然,您尝试为图像传递mp3文件。 您要做的是在res /文件夹中创建一个原始文件夹。

然后当您致电MediaPlayer时:

MediaPlayer md = MediaPlayer.create(context, R.raw.click21);
    md.setOnPreparedListener(new OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            // TODO Auto-generated method stub
            mp.start();
        }
    });
    md.prepareAsync();