Android 为什么处理程序语句是不可转换的代码?
这是我创建的服务类的代码。它在handler.post(timedtask)行给出了一个无法访问的代码错误。我在下面用粗体字评论了一下。请帮我解决这个问题。真要命Android 为什么处理程序语句是不可转换的代码?,android,service,handler,runnable,Android,Service,Handler,Runnable,这是我创建的服务类的代码。它在handler.post(timedtask)行给出了一个无法访问的代码错误。我在下面用粗体字评论了一下。请帮我解决这个问题。真要命 公共类ServerChecker扩展服务{ 通知建筑商和造船商; 意图结果; 处理者; 可运行时间任务; 串总线号; int-mystoppageindex public ServerChecker() { } @Override public void onCreate() { super.onCreate();
公共类ServerChecker扩展服务{ 通知建筑商和造船商; 意图结果; 处理者; 可运行时间任务; 串总线号; int-mystoppageindex
public ServerChecker() {
}
@Override
public void onCreate() {
super.onCreate();
bus_no = PrefsHelper.getFromPreferences(MyApplication.getAppContext(), "BUSNO", "");
mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setTicker("Your bus is arriving")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
resultIntent = new Intent(this, LoginActivity.class);
String url = Config.url + "arrivalwarning.php?bus_no=3-C";
final StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mystoppageindex = Integer.parseInt(PrefsHelper.getFromPreferences(MyApplication.getAppContext(), "STOPPAGEINDEX", ""));
try {
JSONObject jsonObject = new JSONObject(response);
int currentstoppageindex = Integer.parseInt(jsonObject.getString("stoppage_index"));
if (mystoppageindex - currentstoppageindex == 2) {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(MyApplication.getAppContext());
stackBuilder.addParentStack(LoginActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
handler = new Handler();
timedtask = new Runnable() {
@Override
public void run()
{
Log.d("TAG","Runnable");
// VolleySingleton.getInstance().getRequestQueue().add(request);
handler.postDelayed(timedtask, 60000);
}
};
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
handler.post(timedtask); **// WHY IS THIS LINE AN ERROR UNREACHABLE CODE**
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onDestroy() {
super.onDestroy();
handler.removeCallbacks(timedtask);
}
}
publicserverchecker(){
}
@凌驾
public void onCreate(){
super.onCreate();
bus_no=PrefsHelper.getFromPreferences(MyApplication.getAppContext(),“BUSNO”,“”);
mBuilder=(NotificationCompat.Builder)新建NotificationCompat.Builder(此)
.setTicker(“您的巴士即将到达”)
.setSmallIcon(R.mipmap.ic_启动器)
.setContentTitle(“我的通知”)
.setContentText(“你好,世界!”)
.setDefaults(通知.DEFAULT\u声音)
.setAutoCancel(真);
resultIntent=新意图(这是LoginActivity.class);
字符串url=Config.url+“arrivalwarning.php?bus_no=3-C”;
final StringRequest=new StringRequest(request.Method.GET,url,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
mystoppageindex=Integer.parseInt(PrefsHelper.getFromPreferences(MyApplication.getAppContext(),“STOPPAGEINDEX”,”);
试一试{
JSONObject JSONObject=新JSONObject(响应);
int currentstoppageindex=Integer.parseInt(jsonObject.getString(“停止索引”);
如果(mystoppageindex-currentstoppageindex==2){
TaskStackBuilder stackBuilder=TaskStackBuilder.create(MyApplication.getAppContext());
addParentStack(LoginActivity.class);
stackBuilder.addNextIntent(resultIntent);
悬而未决的结果悬而未决的结果=
stackBuilder.GetPendingEvent(0,PendingEvent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingContent);
通知经理通知经理=
(NotificationManager)getSystemService(上下文通知服务);
mNotificationManager.notify(0,mBuilder.build());
}
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
}
});
handler=新的handler();
timedtask=newrunnable(){
@凌驾
公开募捐
{
Log.d(“标记”、“可运行”);
//VolleySingleton.getInstance().getRequestQueue().add(请求);
handler.postDelayed(timedtask,60000);
}
};
}
@凌驾
公共int onStartCommand(Intent Intent、int标志、int startId){
返回super.onStartCommand(intent、flags、startId);
handler.post(timedtask);**//为什么此行是一个无法访问的错误代码**
}
@凌驾
公共IBinder onBind(意向){
//TODO:将通信通道返回到服务。
抛出新的UnsupportedOperationException(“尚未实现”);
}
@凌驾
公共空间{
super.ondestory();
handler.removeCallbacks(timedtask);
}
}
这里有:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
handler.post(timedtask); **// WHY IS THIS LINE AN ERROR UNREACHABLE CODE**
}
因此,为了回答您的问题,我们需要知道您希望java如何在已返回的方法中执行语句…“为什么此行是一个无法访问的错误代码”-因为您在
return
语句之后有它。把它移到前面。