应用程序显示强制关闭仅在启动模拟器/电话时,因为广播接收器显示异常

时间:2012-05-20 07:33:17

标签: android broadcastreceiver forceclose

应用程序仅在重启模拟器/手机时显示强制关闭。它有两个广播接收器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);

1 个答案:

答案 0 :(得分:1)

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

  

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