如何解决android中的致命异常计时器-0?
我想检查网络状态,如果网络未连接,则表示我将在页面中显示警报对话框 这是我的密码如何解决android中的致命异常计时器-0?,android,android-networking,Android,Android Networking,我想检查网络状态,如果网络未连接,则表示我将在页面中显示警报对话框 这是我的密码 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);<br> setContentView(R.layout.activity_main); // make the activity visible Timer t
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);<br>
setContentView(R.layout.activity_main);
// make the activity visible
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
ServicesLayer objService = new ServicesLayer();
boolean status = objService.connectedToNetwork(this);
System.out.println("status: " + status);
if(objService.connectedToNetwork(this)){
callService();
}else{
System.out.println("Inside Network Else");
// Display message and set flag not connected
showAlertDialog(this, "Network Connection", "Connection to network is required for proper use of the iHelpPlus. Would you like to enable it now?" );
}
}
}, 1000);
}
@SuppressWarnings("deprecation")
public void showAlertDialog(Context context, String title, String message) {<br/>
AlertDialog alertDialog = new AlertDialog.Builder(context).create();<br/>
// Setting Dialog Title
alertDialog.setTitle(title);
// Setting Dialog Message
alertDialog.setMessage(message);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
// Showing Alert Message
alertDialog.show();
}
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//使活动可见
定时器=新定时器();
timer.schedule(新TimerTask(){
@凌驾
public void run(){
ServicesLayer objService=新ServicesLayer();
布尔状态=objService.connectedtonework(this);
System.out.println(“状态:+状态”);
if(objService.ConnectedNetwork(本)){
callService();
}否则{
System.out.println(“内部网络其他”);
//显示消息和设置标志未连接
showAlertDialog(此“网络连接”,“连接到网络是正确使用iHelpPlus所必需的。是否立即启用它?”);
}
}
}, 1000);
}
@抑制警告(“弃用”)
public void showAlertDialog(上下文上下文、字符串标题、字符串消息){
AlertDialog AlertDialog=新建AlertDialog.Builder(上下文).create();
//设置对话框标题
alertDialog.setTitle(标题);
//设置对话框消息
alertDialog.setMessage(消息);
//设置OK按钮
alertDialog.setButton(“确定”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
完成();
}
});
//显示警报消息
alertDialog.show();
}
如果网络已连接,则表示它工作正常。。。否则,应用程序将以强制关闭错误关闭
如何在我的申请中解决上述问题
请任何人帮帮我