老师为什么这里会抛出异常
2019-04-27 16:52:56.007 11383-11383/com.example.servicetest D/MyService: onCreate executed
2019-04-27 16:52:56.008 11383-11383/com.example.servicetest D/MyService: onStartCommand executed
2019-04-27 16:53:06.980 11383-11383/com.example.servicetest D/MyService: onBind executed
2019-04-27 16:53:06.982 11383-11383/com.example.servicetest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.servicetest, PID: 11383
java.lang.RuntimeException: Unable to bind to service com.example.servicetest.MyService@eccd01a with Intent { cmp=com.example.servicetest/.MyService }: java.lang.UnsupportedOperationException: Not yet implemented
at android.app.ActivityThread.handleBindService(ActivityThread.java:3445)
at android.app.ActivityThread.-wrap2(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.UnsupportedOperationException: Not yet implemented
at com.example.servicetest.MyService.onBind(MyService.java:36)
at android.app.ActivityThread.handleBindService(ActivityThread.java:3431)
at android.app.ActivityThread.-wrap2(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
代码在这里:
package com.example.servicetest; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class MyService extends Service { public MyService() { } @Override public void onCreate() { Log.d("MyService","onCreate executed"); super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { Log.d("MyService","onStartCommand executed"); return super.onStartCommand(intent, flags, startId); } @Override public void onDestroy() { super.onDestroy(); Log.d("MyService","onDestroy executed"); } @Override public IBinder onBind(Intent intent) { // TODO: Return the communication channel to the service. Log.d("MyService","onBind executed"); throw new UnsupportedOperationException("Not yet implemented"); } @Override public boolean onUnbind(Intent intent) { Log.d("MyService","onunbind executed"); return super.onUnbind(intent); } }
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 116 份
- 解答问题 1012 个
本阶段是提升项目经验的必备,除Android开发的高级控件,还有Android官方大力推荐的开发语言Kotlin,未来Android发展的方向,最后使用Kotlin来开发热门电商项目。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星