0

该应用程序仅在模拟器/手机重新启动时显示强制关闭。它有两个广播接收器 1 用于检查电话状态和接听电话,其他用于在顶部保留通知图标。接收器监控手机状态仅在启动时给出以下异常,否则应用程序工作正常。日志如下所示

05-20 12:48:15.688: INFO/Andros:AnsTheCall:receiver(218): initialised the receiver
05-20 12:48:15.707: WARN/dalvikvm(218): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-20 12:48:15.827: ERROR/AndroidRuntime(218): FATAL EXCEPTION: main
05-20 12:48:15.827: ERROR/AndroidRuntime(218): java.lang.RuntimeException: Unable to start receiver com.andros.AnsTheCall.AnsTheCallReceiver: java.lang.NullPointerException
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at android.app.ActivityThread.access$3200(ActivityThread.java:125)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at android.os.Looper.loop(Looper.java:123)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at java.lang.reflect.Method.invokeNative(Native Method)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at java.lang.reflect.Method.invoke(Method.java:521)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at dalvik.system.NativeStart.main(Native Method)
05-20 12:48:15.827: ERROR/AndroidRuntime(218): Caused by: java.lang.NullPointerException
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at com.andro.AnsTheCall.AnsTheCallReceiver.onReceive(AnsTheCallReceiver.java:37)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
05-20 12:48:15.827: ERROR/AndroidRuntime(218):     ... 10 more

请帮忙

public class AnsTheCallReceiver extends BroadcastReceiver {

public static final String TAG = "Andros:AnsTheCall:receiver";
public selectedTabType attentFlag = selectedTabType.TYPE_INVALID;

private Intent AnsTheCallServiceIntent = null;
public String contactName = null;
public String contactEmail = "";
public int PhoneNumberCount= 0;

@Override
public void onReceive(Context context, Intent intent) {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    // Check phone state
    String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
    String phoneNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
    String lastPhoneNumber = null;
    Log.i(TAG,"initialised the receiver");

    if (phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING) && prefs.getBoolean("appEnabled", false)) {
        int is_starred = isStarred(context, phoneNumber);
4

1 回答 1

1

检查com.andro.AnsTheCall.AnsTheCallReceiver.onReceive(AnsTheCallReceiver.java:37导致您的服务强制关闭的原因。

12:48:15.827:错误/AndroidRuntime(218):引起:java.lang.NullPointerException 05-20 12:48:15.827:错误/AndroidRuntime(218):在 com.andro.AnsTheCall.AnsTheCallReceiver.onReceive(AnsTheCallReceiver。爪哇:37)05-20 12:48:15.827:

于 2012-05-20T08:30:20.270 回答