我正在创建一个呼叫阻止应用程序,当我添加复选框或单选按钮到我的布局,应用程序开始崩溃。
活动代码。
public void onCreate(Bundle savedInstanceState) {
//final EditText edittext = (EditText) findViewById(R.id.edittext);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit=(EditText)findViewById(R.id.editText);
check=(CheckBox)findViewById(R.id.checkBox);
textview=(TextView)findViewById(R.id.textView);
String Number=edit.getText().toString();
String checked="0";
if(check.isChecked())
checked="1";
else
checked="0";
Intent intent = new Intent(PrefActivity.this, PhoneReceiver.class);
intent.putExtra("check", checked);
intent.putExtra("CELL", Number);
PendingIntent sender= PendingIntent.getBroadcast(
Activity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
}
广播接收机代码
公共void onReceive(上下文、意图){
String incomingNumber;
if (!intent.getAction().equals("android.intent.action.PHONE_STATE")) return;
String extraState = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (extraState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
incomingNumber =intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
//SharedPreferences NUMBER=context.getSharedPreferences("myBlocker",0);
//String num=NUMBER.getString("yolo","yes");
//if (num.contentEquals(incomingNumber) /*|| incomingNumber.contentEquals("+923420050490") || incomingNumber.contentEquals("0342-0050490") || incomingNumber.contentEquals("+92331-7002407")*/) {
String num=intent.getStringExtra("CELL");
String check=intent.getStringExtra("check");
if(incomingNumber.contentEquals(num)) {
//SharedPreferences p = context.getSharedPreferences("myBlocker", 0);
// if (p.getBoolean("blockCalls", false)) {
if(check=="1")
terminateCall(context);
}
}
}
private void terminateCall(Context context) {
try {
Log.v(TAG, "Get getTeleService...");
Object telephonyService = getTelephonyServiceObject(context);
Class telephonyInterface = Class.forName("com.android.internal.telephony.ITelephony");
if (telephonyService != null && telephonyInterface != null) {
getAndInvokeMethod(telephonyInterface, telephonyService, "silenceRinger");
getAndInvokeMethod(telephonyInterface, telephonyService, "endCall");
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "FATAL ERROR: could not connect to telephony subsystem");
Log.e(TAG, "Exception object: " + e);
}
}
private Object getTelephonyServiceObject(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
return m.invoke(tm);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private void getAndInvokeMethod(Class c, Object target, String methodName) {
try {
Method m = c.getMethod(methodName);
m.invoke(target);
} catch (Exception e) {
e.printStackTrace();
}
}
XML文件如下所示
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/layout">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Block This Number"
android:id="@+id/checkBox"
android:layout_below="@+id/editText"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:checked="false" />
</RelativeLayout>
错误日志如下
05-26 20:49:50.085: E/AndroidRuntime(15913): FATAL EXCEPTION: main
05-26 20:49:50.085: E/AndroidRuntime(15913): java.lang.RuntimeException: Unable to start receiver com.javaorigin.test.apk.PhoneReceiver: java.lang.NullPointerException
05-26 20:49:50.085: E/AndroidRuntime(15913): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2277)
05-26 20:49:50.085: E/AndroidRuntime(15913): at android.app.ActivityThread.access$1500(ActivityThread.java:140)
05-26 20:49:50.085: E/AndroidRuntime(15913): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
05-26 20:49:50.085: E/AndroidRuntime(15913): at android.os.Handler.dispatchMessage(Handler.java:99)
05-26 20:49:50.085: E/AndroidRuntime(15913): at android.os.Looper.loop(Looper.java:137)
05-26 20:49:50.085: E/AndroidRuntime(15913): at android.app.ActivityThread.main(ActivityThread.java:4898)
05-26 20:49:50.085: E/AndroidRuntime(15913): at java.lang.reflect.Method.invokeNative(Native Method)
05-26 20:49:50.085: E/AndroidRuntime(15913): at java.lang.reflect.Method.invoke(Method.java:511)
05-26 20:49:50.085: E/AndroidRuntime(15913): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
05-26 20:49:50.085: E/AndroidRuntime(15913): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
05-26 20:49:50.085: E/AndroidRuntime(15913): at dalvik.system.NativeStart.main(Native Method)
05-26 20:49:50.085: E/AndroidRuntime(15913): Caused by: java.lang.NullPointerException
05-26 20:49:50.085: E/AndroidRuntime(15913): at java.lang.String.contentEquals(String.java:1732)
05-26 20:49:50.085: E/AndroidRuntime(15913): at com.javaorigin.test.apk.PhoneReceiver.onReceive(PhoneReceiver.java:39)
05-26 20:49:50.085: E/AndroidRuntime(15913): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2270)
05-26 20:49:50.085: E/AndroidRuntime(15913): ... 10 more
05-26 20:49:50.150: E/android.os.Debug(2260): !@Dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error
05-26 20:49:50.370: E/Bluetooth HS/HF(2818): handlePreciseCallStateChange() mPhone=RINGING, mFCall=IDLE, mBCall=IDLE, mRCall=INCOMING, mCallsetup=1, mCall=0, mCallheld=0
05-26 20:49:50.455: E/BargeInRecognizer(2818): stopBargeIn
05-26 20:50:00.120: E/dalvikvm(17755): Could not find class 'com.amazon.device.messaging.ADM', referenced from method com.whatsapp.App.aN
05-26 20:50:00.165: E/dalvikvm(17755): Could not find class 'com.amazon.device.messaging.ADM', referenced from method com.whatsapp.App.m
05-26 20:50:00.310: E/dalvikvm(17755): Could not find class 'com.whatsapp.adm.ADMMessageHandler', referenced from method com.whatsapp.iz.c
05-26 20:50:00.310: E/dalvikvm(17755): Could not find class 'com.whatsapp.adm.ADMMessageHandler', referenced from method com.whatsapp.iz.c
05-26 20:50:00.670: E/WifiP2pStateTracker(2260): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
05-26 20:50:01.225: E/dalvikvm(17818): Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.hg.a
05-26 20:50:01.520: E/WifiP2pStateTracker(2260): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
05-26 20:50:01.525: E/WifiP2pStateTracker(2260): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
05-26 20:50:01.555: E/WifiP2pStateTracker(2260): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
05-26 20:50:01.560: E/dalvikvm(17755): Could not find class 'com.whatsapp.j_', referenced from method com.whatsapp.xj.<clinit>
05-26 20:50:01.605: E/AuthorizationBluetoothService(13869): Proximity feature is not enabled.
05-26 20:50:01.890: E/WifiP2pStateTracker(2260): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
05-26 20:50:07.760: E/ActivityThread(18347): Failed to find provider info for com.seven.provider.email
05-26 20:50:08.170: E/ActivityThread(18426): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@424e4b38 that was originally bound here
05-26 20:50:08.170: E/ActivityThread(18426): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@424e4b38 that was originally bound here
05-26 20:50:08.170: E/ActivityThread(18426): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:965)
05-26 20:50:08.170: E/ActivityThread(18426): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:859)
05-26 20:50:08.170: E/ActivityThread(18426): at android.app.ContextImpl.bindService(ContextImpl.java:1344)
05-26 20:50:08.170: E/ActivityThread(18426): at android.app.ContextImpl.bindService(ContextImpl.java:1336)
05-26 20:50:08.170: E/ActivityThread(18426): at android.content.ContextWrapper.bindService(ContextWrapper.java:401)
05-26 20:50:08.170: E/ActivityThread(18426): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:156)
05-26 20:50:08.170: E/ActivityThread(18426): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:144)
05-26 20:50:08.170: E/ActivityThread(18426): at com.android.emailcommon.service.AccountServiceProxy.restoreAccountsIfNeeded(AccountServiceProxy.java:115)
05-26 20:50:08.170: E/ActivityThread(18426): at com.android.exchange.ExchangeService$11.run(ExchangeService.java:4020)
05-26 20:50:08.170: E/ActivityThread(18426): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:792)
05-26 20:50:08.170: E/ActivityThread(18426): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:789)
05-26 20:50:08.170: E/ActivityThread(18426): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-26 20:50:08.170: E/ActivityThread(18426): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-26 20:50:08.170: E/ActivityThread(18426): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-26 20:50:08.170: E/ActivityThread(18426): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-26 20:50:08.170: E/ActivityThread(18426): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-26 20:50:08.170: E/ActivityThread(18426): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-26 20:50:08.170: E/ActivityThread(18426): at java.lang.Thread.run(Thread.java:856)
05-26 20:50:09.615: E/Watchdog(2260): !@Sync 2739
05-26 20:50:10.505: E/TinyUCM(1904): Normal is already enabled
05-26 20:50:10.550: E/Bluetooth HS/HF(2818): audioOff(): mPendingScoForA2dp: false, mPendingScoForWbs: false, mConnectedSco: null, mA2dpState: 11, mA2dpSuspended: false, mVoiceRecognitionStarted: false
05-26 20:50:10.670: E/ActivityThread(2818): Failed to find provider info for com.cequint.ecid
05-26 20:50:10.700: E/BargeInRecognizer(2818): stopBargeIn
05-26 20:50:10.755: E/Bluetooth HS/HF(2818): handlePreciseCallStateChange() mPhone=IDLE, mFCall=IDLE, mBCall=IDLE, mRCall=IDLE, mCallsetup=1, mCall=0, mCallheld=0
05-26 20:50:10.755: E/Bluetooth HS/HF(2818): audioOff(): mPendingScoForA2dp: false, mPendingScoForWbs: false, mConnectedSco: null, mA2dpState: 11, mA2dpSuspended: false, mVoiceRecognitionStarted: false
05-26 20:50:17.510: E/MtpService(10955): In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED
05-26 20:50:17.510: E/MtpService(10955): battPlugged Type : 2
05-26 20:50:35.270: E/dalvikvm(19024): Could not find class 'android.telephony.CellInfoCdma', referenced from method com.facebook.common.hardware.CellDiagnosticsSerializer.c
05-26 20:50:35.705: E/dalvikvm(19024): Could not find class 'com.facebook.push.adm.ADMBroadcastReceiver', referenced from method com.facebook.push.adm.ADMPushManager.b
05-26 20:50:39.620: E/Watchdog(2260): !@Sync 2740
05-26 20:50:48.505: E/MtpService(10955): In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED
05-26 20:50:48.505: E/MtpService(10955): battPlugged Type : 2
05-26 20:50:49.105: E/dalvikvm(19104): Could not find class 'android.telephony.CellInfoCdma', referenced from method com.facebook.common.hardware.j.c
05-26 20:50:49.190: E/dalvikvm(19133): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.b
05-26 20:50:49.195: E/dalvikvm(19133): Could not find class 'android.support.v4.app.FragmentActivity', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.b
05-26 20:50:49.250: E/GooglePlayServicesUtil(19133): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 20:50:49.275: E/GooglePlayServicesUtil(19133): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 20:50:49.315: E/GooglePlayServicesUtil(19133): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 20:50:49.345: E/GooglePlayServicesUtil(19133): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 20:50:49.355: E/GooglePlayServicesUtil(19133): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 20:50:49.365: E/GooglePlayServicesUtil(19133): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 20:50:49.395: E/GooglePlayServicesUtil(19133): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 20:50:49.755: E/dalvikvm(19104): Could not find class 'com.facebook.push.adm.ADMBroadcastReceiver', referenced from method com.facebook.push.adm.a.b
05-26 20:50:52.055: E/NotificationService(2260): Ignoring notification with icon==0: Notification(pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x62 kind=[null]) tickerText=null contactCharSeq=null when=1432655452055 threadId=0
05-26 20:51:00.030: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:51:05.340: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:51:05.355: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:51:05.715: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:51:09.625: E/Watchdog(2260): !@Sync 2741
05-26 20:51:11.280: E/LockPatternKeyguardView(2260): mIsVoiceUnlockOn=false
05-26 20:51:11.960: E/CircleShortcutWidget(2260): density = 320
05-26 20:51:11.960: E/CircleShortcutWidget(2260): pkg name =com.android.contacts, activityName=com.android.contacts.activities.DialtactsActivity
05-26 20:51:12.060: E/CircleShortcutWidget(2260): pkg name =com.sec.chaton, activityName=com.sec.chaton.HomeActivity
05-26 20:51:12.145: E/CircleShortcutWidget(2260): pkg name =com.google.android.googlequicksearchbox, activityName=com.google.android.googlequicksearchbox.SearchActivity
05-26 20:51:12.375: E/CircleShortcutWidget(2260): pkg name =com.android.browser, activityName=com.android.browser.BrowserActivity
05-26 20:51:12.440: E/CircleShortcutWidget(2260): pkg name =com.sec.android.app.camera, activityName=com.sec.android.app.camera.Camera
05-26 20:51:12.800: E/WakeUpCmdRecognizer(2260): WakeUpCmdRecognizer Create
05-26 20:51:12.810: E/WakeUpCmdRecognizer(2260): setLanguage : en
05-26 20:51:12.810: E/WakeUpCmdRecognizer(2260): Country : US
05-26 20:51:12.810: E/WakeUpCmdRecognizer(2260): sVoiceLanguage : en-US
05-26 20:51:12.815: E/WakeUpCmdRecognizer(2260): isSamsungWakeUpLibExist : true
05-26 20:51:12.815: E/WakeUpCmdRecognizer(2260): isSensoryWakeUpLibExist : true
05-26 20:51:12.820: E/WakeUpCmdRecognizer(2260): init
05-26 20:51:12.820: E/VoiceEngineWrapper(2260): getInstance() : get existed VoiceEngine
05-26 20:51:12.820: E/SensoryEngineWrapper(2260): getInstance() : get existed SensoryJNI
05-26 20:51:12.820: E/VoiceEngine(2260): setIsRunningVoiceEngine mode : true
05-26 20:51:12.820: E/VoiceEngineWrapper(2260): getInstance() : get existed VoiceEngine
05-26 20:51:12.820: E/SensoryEngineWrapper(2260): getInstance() : get existed SensoryJNI
05-26 20:51:13.185: E/LocationReceiver(16720): Received bad location: null
05-26 20:51:13.835: E/KeyguardViewMediator(2260): 2. Lockscreen lock
05-26 20:51:13.835: E/KeyguardViewMediator(2260): Phone is boot completed. so can broadcast
05-26 20:51:14.670: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:51:19.790: E/MtpService(10955): In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED
05-26 20:51:19.790: E/MtpService(10955): battPlugged Type : 2
05-26 20:51:19.920: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:51:30.195: E/DBG_DM(19330): Warning!!! [v5_1209_1_2][Line:1813][xdmCheckSystemRooting] Device is ok
05-26 20:51:30.200: E/DBG_DM(19330): Warning!!! [v5_1209_1_2][Line:1733][xdmGetServiceManager] java.lang.NullPointerException
05-26 20:51:30.200: E/DBG_DM(19330): Warning!!! [v5_1209_1_2][Line:964][xdmGetTopActivityName] activityManager is null!!
05-26 20:51:39.625: E/Watchdog(2260): !@Sync 2742
05-26 20:51:43.390: E/WifiP2pStateTracker(2260): getNetworkInfo : NetworkInfo: type: WIFI_P2P[], state: UNKNOWN/IDLE, reason: (unspecified), extra: (none), roaming: false, failover: false, isAvailable: true
05-26 20:51:43.565: E/DBG_DM(19330): Warning!!! [v5_1209_1_2][Line:1813][xdmCheckSystemRooting] Device is ok
05-26 20:51:53.795: E/MtpService(10955): In MTPAPP onReceive:android.intent.action.BATTERY_CHANGED
05-26 20:51:53.795: E/MtpService(10955): battPlugged Type : 2
05-26 20:52:00.820: E/MtpServerJNI(19368): could not open MTP driver, errno: 2
05-26 20:52:00.840: E/MtpServerJNI(19368): server is null in run
05-26 20:52:00.840: E/MtpServerJNI(19368): server is null in cleanup
05-26 20:52:05.700: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:52:09.625: E/Watchdog(2260): !@Sync 2743
05-26 20:52:10.760: E/WifiHW(2260): ##################### set firmware type 0 #####################
05-26 20:52:21.320: E/ResourceType(19403): getSupportListinCSC: cannot open file
05-26 20:52:21.320: E/ResourceType(19403): The locale in CSC is empty.
看起来这行代码导致了异常:
if(incomingNumber.contentEquals(num)) {
incomingNumber为null,并且null没有contentEquals方法,这就是它引发异常的原因。
因此,您需要传递keyTphone onyManager的字符串值。在发送之前EXTRA_INCOMING_NUMBER意图。
代码中还有另一个问题:
if(check=="1")
如果(“1”。contentEquals(check)),则应更改为
我尝试使用Android studio在谷歌地图上创建位置标记,并从Firebase实时数据库中获取位置。当我将Firebase实时数据库添加到我的应用程序中后,它就一直崩溃。请帮帮忙。下面是MapsActivity.java代码 这似乎是个问题 Path是一个唯一的关键字,我不知道如何创建Path,所以我尝试了substring并将其转换为float。谢谢你
当我尝试在Android Studio3中添加图像时,应用程序就会崩溃。请帮帮忙。 logcat: activity_main.xml 主要活动.java 当我删除ImageView时,应用程序就可以正常工作了。我已经尝试了一切,调整图像大小,重新安装android Studio。 有人能把问题弄清楚吗?
问题内容: 每次我从Eclipse导出签名应用程序并将apk文件安装到手机上时,该应用程序都会崩溃。这仅在启用Proguard的情况下发生。 这是我的保护文件 我运行了adb logcat命令来检查崩溃报告。以下是我认为很重要的报告摘要: 第二段: 如果有人可以帮助我,我将非常感谢并接受您的回答。 更新: 所以我将这些添加到我的proguard文件中 现在启用Proguard时出现与Jackson
在以前的代码上,谁医生帮了我 现在,android应用程序在我的手机上运行时崩溃了,这是错误日志 第一个问题是在我用相机扫描二维码后,它不能显示在二维码的结果进入 第二个问题是,我从存储器中选择了一个QRcode图像,然后点击确认,它崩溃了 下面是我认为的问题 类型不匹配:推断的类型是Uri?但乌里是意料之中的 冗余SAM构造函数 'onRequestPermissionsResult(Int,数
我们正在开发一款Android应用程序,它可以捕获图像并将其转换为位图,然后发布到Rest服务。 创建位图时,我们使用BitmapFactory。选项。isSample Size配置为值4,这在除HTC One之外的所有设备上都可以正常工作。HTC one中的图像失真。 当我们将该值更改为1时,它在HTC one上显示了良好的图像,但由于内存问题,应用程序在所有其他设备上崩溃。 该问题与可用堆大小
我的应用程序在我试图实现的闪屏后崩溃。我不知道问题发生在哪里。 我试着用两个小时来解决这个问题,甚至还研究了一下网络,但不知怎么的,我没能让它工作。也许你们可以看看代码,给我一些提示?我会很感激的。 AndroidManifest。xml launch_screen.xml activity_main.xml 风格。xml 主要活动。JAVA 所以会显示实际的启动屏幕,但之后应用程序就会崩溃。我不