我是android编程的初学者
我的问题是...
我想播放背景音乐。
所以我读了这样的代码
public class Welcome extends Activity {
/** Called when the activity is first created. */
MediaPlayer player;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
player=MediaPlayer.create(Welcome.this, R.raw.song);
player.start();
但是此代码在模拟器中不起作用。发生了错误...
我的Logcat在这里。
03-05 15:36:36.588: ERROR/AndroidRuntime(954): FATAL EXCEPTION: main
03-05 15:36:36.588: ERROR/AndroidRuntime(954): java.lang.RuntimeException: Unable to start activity ComponentInfo{younkyung.app.lord_of_spelling/younkyung.app.lord_of_spelling.Welcome}: java.lang.NullPointerException
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.os.Looper.loop(Looper.java:123)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at java.lang.reflect.Method.invoke(Method.java:521)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at dalvik.system.NativeStart.main(Native Method)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): Caused by: java.lang.NullPointerException
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at younkyung.app.lord_of_spelling.Welcome.onCreate(Welcome.java:25)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-05 15:36:36.588: ERROR/AndroidRuntime(954): ... 11 more
我不明白怎么了...
请帮忙..! ...
最佳答案
您需要使用supported file formats之一。 WMA不是其中之一。