调用intent.getExtras()时,ICS崩溃

时间:2011-12-28 10:06:04

标签: android exception crash android-intent android-service

仅在某些 ICS设备上发生这种情况。

我的应用程序正在做的基本上是等待广播然后以意图启动服务。

意图附加了一个包,将用

读出
@Override
public void onStart(Intent intent, int startId) {
    sets = new SettingsClass(this);
    Bundle extras = intent.getExtras();

但是,在导致此堆栈跟踪的某些ICS设备上:

java.lang.RuntimeException: Unable to start service de.bulling.smstalk.Services.TTS@418218f8 with null: java.lang.NullPointerException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2375)
at android.app.ActivityThread.access$1900(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at de.bulling.smstalk.Services.TTS.onStart(TTS.java:48)
at android.app.Service.onStartCommand(Service.java:438)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2358)
... 10 more
java.lang.NullPointerException
at de.bulling.smstalk.Services.TTS.onStart(TTS.java:48)
at android.app.Service.onStartCommand(Service.java:438)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2358)
at android.app.ActivityThread.access$1900(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)

提到的第48行读取附加内容的行。我曾经用这样的另一个服务发出了同样的例外。

现在问题是:我该如何解决这个问题?有没有其他方法可以启动服务并传递数据,还是在错误的地方调用getExtras()

谢谢!

1 个答案:

答案 0 :(得分:2)

看起来onStart可能是deprecated,您是否尝试过该方法

@Override

public int onStartCommand(Intent intent, int flags, int startId)