【问题标题】:Error While using Paging 3 in FireStore Ui Recycler Paging Adapter: PagingConfig cannot be converted to Config在 FireStore Ui Recycler Paging Adapter 中使用 Paging 3 时出错:PagingConfig 无法转换为 Config
【发布时间】:2021-10-29 21:45:26
【问题描述】:
/*--- Load News Feed in Recycler View ---*/
    private void loadNewsFeed(){


        CollectionReference collectionReference = firebaseFirestore.collection("News Feed");
        query =  collectionReference
            .orderBy("newsFeedId", Query.Direction.DESCENDING);
        

        PagingConfig config = new PagingConfig(1,
                                               1,
                                               false);


        FirestorePagingOptions<ModelNewsFeed> options = new FirestorePagingOptions.Builder<ModelNewsFeed>()
                .setLifecycleOwner(this)
                .setQuery(query, config, ModelNewsFeed.class)
                .build();



        adapterNewsFeedListFireStorePaginationAds = new AdapterNewsFeedListFireStorePaginationAds(options, this);

        newsFeedRv.setAdapter(adapterNewsFeedListFireStorePaginationAds);




    }

我在“.setQuery(query, config, ModelNewsFeed.class)”处收到错误

Error: .setQuery(query, config, ModelNewsFeed.class)
                ^
    method Builder.setQuery(Query,Config,Class<ModelNewsFeed>) is not applicable
      (argument mismatch; PagingConfig cannot be converted to Config)
    method Builder.setQuery(Query,Config,SnapshotParser<ModelNewsFeed>) is not applicable
      (argument mismatch; PagingConfig cannot be converted to Config)

纠正这个错误的解决方案是什么?

我正在尝试从

迁移

第 2 页: androidx.paging:paging-runtime:2.1.2

第 3 页:

androidx.paging:paging-runtime:3.0.1.

Error Screen Shot

【问题讨论】:

  • 你试过只打电话给.setQuery(query, ModelNewsFeed.class)吗?是这样的吗?
  • 我必须使用分页。和 .setQuery(query, ModelNewsFeed.class) 非常适合一次加载所有项目。我已按照firebaseopensource.com/projects/firebase/firebaseui-android/… 中提到的步骤进行操作。但是对于分页它给了我一个错误。
  • 我已经更新了错误消息的屏幕截图,我得到了更多的说明。
  • 你是如何导入 PagingConfig 的?请编辑您的问题并添加相应的行。
  • 首先我替换了gradle文件中的依赖。然后从 firebaseopensource.com/projects/firebase/firebaseui-android/… 复制了 PagingConfig 的代码。按 Alt+Enter 导入后,这是在 Java 文件“import androidx.paging.PagingConfig;”中导入的。然后这个错误开始出现。如果还有什么想知道的,请告诉我。

标签: android google-cloud-firestore android-recyclerview pagination android-paging-3


【解决方案1】:

@dlam 在此线程的评论部分为我提供了解决方案。我的 android 工作室使用的是 Firebase ui 版本 7.1.1,它必须是 @dlam 提到的 8.0.0。并解决了问题。

谢谢@dlam。 https://stackoverflow.com/users/1452382/dlam

【讨论】:

    猜你喜欢
    • 2020-12-15
    • 1970-01-01
    • 2023-01-18
    • 2022-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多