gpt4 book ai didi

java - 无法解析方法 addOnCompleteListener

转载 作者:行者123 更新时间:2023-12-02 11:01:43 24 4
gpt4 key购买 nike

我的程序的一部分如下所示。我尝试与 firebase 一起使用。我对这个方法有很多问题。

subscribeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Subscribing to news topic");
FirebaseMessaging.getInstance().subscribeToTopic("news").addOnCompleteListener(new OnCompleteListener <Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
String msg = getString(R.string.msg_subscribed);
if (!task.isSuccessful()) {
msg = getString(R.string.msg_subscribe_failed);
}
Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
}
});

这是错误:

cannot resolve method addOnCompleteListener anonymous com.google.android.gms.tasks.OnCompleteListener<java.lang.Void>

我的build.gradle

dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//implementation 'com.google.protobuf:protobuf-java:2.6.1'
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.8.1'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
compile 'jp.wasabeef:blurry:2.1.1'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.crystal:crystalrangeseekbar:1.1.3'
compile 'wzd.anarchy:library:unspecified'
implementation 'com.android.support:support-v4:25.4.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
testCompile 'junit:junit:4.12'
compile 'com.google.protobuf:protobuf-java:3.0.0-beta-3'
dependencies {
compile 'com.github.TouchBoarder:weekdays-buttons-bar:v1.0.2'
}
compile 'com.jakewharton:butterknife:8.6.0'
compile 'com.firebase:firebase-jobdispatcher:0.5.2'
implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
compile 'com.google.android.gms:play-services:12.0.1'
compile "com.polidea.rxandroidble:rxandroidble:1.4.3"
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'io.reactivex.rxjava2:rxjava:2.1.8'
}


apply plugin: 'com.google.gms.google-services'

如果我添加实现,我会看到错误:无法访问 zzbgl找不到 com.google.android.gms.internal.zzbgl 的类文件

最佳答案

您收到该错误是因为缺少一些依赖项。

FirebaseMessaging.getInstance().subscribeToTopic("news")

返回 Task<Void>目的。为了在该对象上附加监听器,您需要将以下依赖项添加到 build.gradle 文件:

implementation 'com.google.firebase:firebase-messaging:17.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'

根据您的 build.gradle 文件,您还应该更改这行代码:

compile 'com.google.android.gms:play-services:12.0.1'

implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-analytics:16.0.1'

并且不要忘记添加:

classpath 'com.google.gms:google-services:4.0.1'

在另一个 build.gradle 文件中。

关于java - 无法解析方法 addOnCompleteListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51282737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com