android程序报错Caused by: java.lang.NullPointerExceptionat,下面是具体代码,求指导~~
04-2907:32:22.450:E/AndroidRuntime(2601):Causedby:java.lang.NullPointerException04-29...
04-29 07:32:22.450: E/AndroidRuntime(2601): Caused by: java.lang.NullPointerException
04-29 07:32:22.450: E/AndroidRuntime(2601): at com.tarena.fashionmusic.main.MainActivity.onStart(MainActivity.java:339)
04-29 07:32:40.190: E/AndroidRuntime(2654): Caused by: java.lang.NullPointerException
04-29 07:32:40.190: E/AndroidRuntime(2654): at com.tarena.fashionmusic.service.MusicPlayerService.onCreate(MusicPlayerService.java:235)
代码贴出来:com.tarena.fashionmusic.main.MainActivity.java
protected void onStart() {
super.onStart();
// 启动的时候更新 页面当前播放信息
sendBroadcast(new Intent(Constant.ACTION_UPDATE_ALL));
position = MyApplication.musicPreference.getsaveposition(context);
ShowNowPlayMusic();
}
com.tarena.fashionmusic.service.MusicPlayerService.java
public void onCreate() {
super.onCreate();
sp = getSharedPreferences("service", 0);
sp.edit().putBoolean("isStart", true).commit();
// 广播接收器
mReceiver = new MyReciever();
apReciver = new apwReciver();
phoneStatRec = new PhoneStatRec();
updataintent = new Intent(Constant.ACTION_UPDATE);
//onCompletionListener = new OnCompletionListener();
context = this;
mPlayer = MyApplication.mediaPlayer;
manager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
mPlayer.setOnCompletionListener(new OnCompletionListener() {
/**
* 音乐播放完成的处理方法
*/
@Override
public void onCompletion(MediaPlayer mp) {
next();// 播放下一首
}
});
// 当前播放的音乐列表
musicList = ((MyApplication) getApplication()).getMusics();
// 当前播放音乐的索引
current = MyApplication.musicPreference.getsaveposition(this);
} 展开
04-29 07:32:22.450: E/AndroidRuntime(2601): at com.tarena.fashionmusic.main.MainActivity.onStart(MainActivity.java:339)
04-29 07:32:40.190: E/AndroidRuntime(2654): Caused by: java.lang.NullPointerException
04-29 07:32:40.190: E/AndroidRuntime(2654): at com.tarena.fashionmusic.service.MusicPlayerService.onCreate(MusicPlayerService.java:235)
代码贴出来:com.tarena.fashionmusic.main.MainActivity.java
protected void onStart() {
super.onStart();
// 启动的时候更新 页面当前播放信息
sendBroadcast(new Intent(Constant.ACTION_UPDATE_ALL));
position = MyApplication.musicPreference.getsaveposition(context);
ShowNowPlayMusic();
}
com.tarena.fashionmusic.service.MusicPlayerService.java
public void onCreate() {
super.onCreate();
sp = getSharedPreferences("service", 0);
sp.edit().putBoolean("isStart", true).commit();
// 广播接收器
mReceiver = new MyReciever();
apReciver = new apwReciver();
phoneStatRec = new PhoneStatRec();
updataintent = new Intent(Constant.ACTION_UPDATE);
//onCompletionListener = new OnCompletionListener();
context = this;
mPlayer = MyApplication.mediaPlayer;
manager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
mPlayer.setOnCompletionListener(new OnCompletionListener() {
/**
* 音乐播放完成的处理方法
*/
@Override
public void onCompletion(MediaPlayer mp) {
next();// 播放下一首
}
});
// 当前播放的音乐列表
musicList = ((MyApplication) getApplication()).getMusics();
// 当前播放音乐的索引
current = MyApplication.musicPreference.getsaveposition(this);
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询