类要么必须声明为抽象或实现抽象方法 [英] Class must either be declared abstract or implement abstract method
问题描述
我发现在GitHub上一个小型的Deezer的球员,但我认为它已经在Eclipse codeD。然而,我在Android中工作室工作。
I have found a mini Deezer player on github, but I think it's been coded in Eclipse. I however work in Android Studio.
Beeing我的第一个Android应用它必须是一个noob问题,但我被困在这:
Beeing my first Android app it must be a noob question, but I am stuck on this:
`私人DialogListener mDeezerDialogListener =新的 DialogListener (){
` private DialogListener mDeezerDialogListener = new DialogListener() {
@Override
public void onComplete(Bundle values) {
// store the current authentication info
SessionStore sessionStore = new SessionStore();
sessionStore.save(mDeezerConnect, LoginActivity.this);
// Launch the Home activity
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(intent);
}
@Override
public void onDeezerError(final DeezerError deezerError) {
Toast.makeText(LoginActivity.this, R.string.deezer_error_during_login,
Toast.LENGTH_LONG).show();
}
@Override
public void onError(final DialogError dialogError) {
Toast.makeText(LoginActivity.this, R.string.deezer_error_during_login,
Toast.LENGTH_LONG).show();
}
@Override
public void onCancel() {
Toast.makeText(LoginActivity.this, R.string.login_cancelled, Toast.LENGTH_LONG).show();
}
@Override
public void onOAuthException(OAuthException oAuthException) {
Toast.makeText(LoginActivity.this, R.string.invalid_credentials, Toast.LENGTH_LONG)
.show();
}
};`
的粗体功能是给我其内容的错误:
The bold function is giving me an error which reads:
班从DialogListener派生的匿名类'必须是
声明抽象或实现抽象方法
在DialogListener'onException的(异常)。
Class 'Anonymous class derived from DialogListener' must either be declared abstract or implement abstract method 'onException(Exception)' in 'DialogListener'.
我不知道是什么问题,而是雪上加霜,一切都很好,第一@Override,但第二,第三和最后一个给我这个错误:
I have no idea what is the problem, but to add insult to injury, all is well with the first @Override, but the second, the third and the last one give me this error:
错误:(91 17)错误:方法不覆盖或实现方法
从超
Error:(91, 17) error: method does not override or implement a method from a supertype
这应该是一个工作code片段,还等什么这里的问题是,为什么在一些@Overrides的投诉呢?
This is supposed to be a working code snippet, so what is the problem here, why the complaints on some of the @Overrides?
连接这两个错误?
EDIT1:
至于建议我增加了一个功能:
As suggested I added another function:
@Override
public void onException(Exception exception) {
}
和第一个错误就走开了。会不会是github上原来的code是为SDK的previous版本,diferently没有东西写的?
and the first error went away. Could it be that the original code on github was written for a previous version of SDK, that did stuff diferently?
@Override错误留了下来。但据我所看到的,这些都是onException的子例外?
@Override errors stayed. but as far as I can see, those are sub-exceptions of onException?
EDIT2:
这是在Deezer SDK中定义:
This is defined in the Deezer SDK:
import com.deezer.sdk.network.connect.event.DialogListener;
我在看他们的文档,并在方法摘要中提到: onCancel()
,的onComplete(束值)
, onException的(例外的例外)
。
它还说: onException的无效(异常除外)时,异常在验证过程中被抛出
被调用。
以下例外情况可能会提出: OAuthException
, DeezerError
, DialogError
。
The following exceptions may be raised :
OAuthException
,
DeezerError
,
DialogError
.
我想我会在这里发布的所有附加数据。
I think I will post all additional data here.
EDIT3:
这是我如何重写了code:
This is how I rewrote the code:
@Override
public void onException(Exception exception) {
if(exception instanceof DeezerError){
Toast.makeText(LoginActivity.this, R.string.deezer_error_during_login,
Toast.LENGTH_LONG).show();
}
else if(exception instanceof DialogError){
Toast.makeText(LoginActivity.this, R.string.deezer_error_during_login,
Toast.LENGTH_LONG).show();
}
else if(exception instanceof OAuthException){
Toast.makeText(LoginActivity.this, R.string.invalid_credentials, Toast.LENGTH_LONG)
.show();
}
else{
//not implemented?
}
}
发出警告:条件异常的instanceof OAuthException始终是假
Gives a warning: Condition 'exception instanceof OAuthException' is always 'false'.
我将不得不对这项工作,但是这是现在不同的问题。
I will have to work on that, but this is now a different question.
谢谢你们!
推荐答案
正如您在您的评论提到,该文档的Deezer说,DialogListener有3种方法:
onCancel()的onComplete(束值),onException的(例外的例外)。
As you mention in your comment, the Deezer doc says that DialogListener has 3 methods: onCancel(), onComplete(Bundle values), onException(Exception exception).
所以,你必须实现只有这3个功能。
So you have to implements ONLY these 3 functions.
@Override
public void onComplete(Bundle values) {
// store the current authentication info
SessionStore sessionStore = new SessionStore();
sessionStore.save(mDeezerConnect, LoginActivity.this);
// Launch the Home activity
Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(intent);
}
@Override
public void onCancel() {
Toast.makeText(LoginActivity.this, R.string.login_cancelled, Toast.LENGTH_LONG).show();
}
@Override
public void onException(Exception e) {
// ...
}
和删除其他方法:onError的,等等。也许你的例子,正如你提到的,对于SDK的另一个版本。
And remove the other methods: onError, etc. Maybe you example, as you suggest, is for another version of the SDK.
请注意:我不使用Android的工作室,但在Eclipse你有一个命令来自动创建需要的方法(空,以提'TODO')。也许同样存在于Android的工作室?
Note: I don't use Android Studio, but in Eclipse you have a command to automatically create needed methods (empty, with mention 'TODO'). Maybe the same exists in Android Studio?
这篇关于类要么必须声明为抽象或实现抽象方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!