Java 标记“”上的语法错误;扩展;在服务中实现PhoneStateListener时引发
我试图在服务中实现电话状态侦听器,但收到错误:Java 标记“”上的语法错误;扩展;在服务中实现PhoneStateListener时引发,java,android,service,listener,telephonymanager,Java,Android,Service,Listener,Telephonymanager,我试图在服务中实现电话状态侦听器,但收到错误: Syntax error on token "extends", throws expected 但当我将扩展更改为抛出时,我会收到3个新错误,说明: EndCallListener cannot be resolved to a type EndCallListener cannot be resolved to a type No exception of type PhoneStateListener can be thrown; an
Syntax error on token "extends", throws expected
但当我将扩展更改为抛出时,我会收到3个新错误,说明:
EndCallListener cannot be resolved to a type
EndCallListener cannot be resolved to a type
No exception of type PhoneStateListener can be thrown; an exception type must be a subclass of Throwable
有什么建议吗
阿曼尼·斯旺
public void onCreate() extends PhoneStateListener {
EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
}
public void onCallStateChanged(int state, String incomingNumber) {
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
// set number of calls to 1 in SharedPreferences
SharedPreferences pref = getApplicationContext()
.getSharedPreferences("DataCountService", 0);
Editor editor = pref.edit();
editor.putString("calls", "1");
editor.commit();
}
如果onCreate实际上是一个方法,正如返回类型“void”和名称后的括号所示,则不能在那里使用extends。只有类可以从其他类继承
public class ClassName extends ParentClassName { //class code }
在这里你可以找到关于继承的神谕