开发者

Service Causing Unexpected Close

I am creating a game app and I have a few activities for the different screens. I have a service I am using to play music through out the activities. A really simple service, I have the title screen with image buttons to turn it on and off. Now I am getting a unexpected close and this error message from eclipse:

[2011-05-19 19:50:04 - ddms]null
java.lang.NullPointerException
    at com.android.ddmlib.Client.sendAndConsume(Client.java:571)
    at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
    at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
    at com.android.ddmlib.Client.getJdwpPacket(Client.java:670)
    开发者_StackOverflow社区at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
    at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

EDIT: Code For Service

public class BGMusic extends Service {

MediaPlayer player;

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    player = MediaPlayer.create(this, R.raw.still_wana);
}

public void onStart(Intent intent, int startId) {
    super.onCreate();
    player.start();
}

@Override
public void onDestroy() {
    super.onDestroy();
    player.stop();
}

}

EDIT: Console Android Msg

Starting activity com.android.hitmanassault.HitmanTitle on device emulator-5554 ActivityManager: DDM dispatch reg wait timeout ActivityManager: Can't dispatch DDM chunk 52454151: no handler defined ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.android.hitmanassault/.HitmanTitle }


java.lang.NullPointerException
    at com.android.ddmlib.Client.sendAndConsume(Client.java:571)

You have a null pointer problem at line 571 of Client.java.

Probably caused by passing a parameter that can't be null as null. Maybe this for example:

R.raw.still_wana


You are calling the wrong super method in onStart():

public void onStart(Intent intent, int startId) {
    super.onCreate();

It should be:

public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜