我在
github上找到了一个迷你Deezer播放器,但我认为它已经在
Eclipse中编码了.然而,我在
Android Studio工作.
Beeing我的第一个Android应用程序它必须是一个noob问题,但我坚持这个:
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();
}
};`
粗体函数给出了一个错误,内容如下:
Class ‘Anonymous class derived from DialogListener’ must either be
declared abstract or implement abstract method
‘onException(Exception)’ in ‘DialogListener’.
我不知道是什么问题,但是为了加重侮辱伤害,第一个@Override一切都很好,但是第二个,第三个和最后一个给了我这个错误:
Error:(91, 17) error: method does not override or implement a method
from a supertype
这应该是一个有效的代码片段,所以这里有什么问题,为什么对某些@Overrides的投诉呢?
这两个错误是否相关?
EDIT1:
建议我添加另一个功能:
@Override
public void onException(Exception exception) {
}
并且第一个错误消失了.可能是github上的原始代码是为以前版本的SDK编写的,它做了不同的事情吗?
@Override错误仍然存在.但据我所知,那些是onException的子例外?
EDIT2:
这在Deezer SDK中定义:
import com.deezer.sdk.network.connect.event.DialogListener;
我正在查看他们的文档,并在“方法摘要”中提到:
onCancel()
onComplete(Bundle values),
onException(异常异常).
它还说:
在验证过程中抛出异常时,将调用void onException(异常异常).
可能会引发以下异常:
OAuthException,
DeezerError,
DialogError.
我想我会在这里发布所有其他数据.
EDIT3:
这就是我重写代码的方式:
@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?
}
}
发出警告:条件’OAuthException的异常实例’始终为’false’.
我将不得不继续努力,但这是一个不同的问题.