草庐IT

java - 无法解析符号 "FirebaseRecyclerOptions"

coder 2023-12-29 原文

我正在通过 Firebase 制作聊天信使,但我的 Android Studio 2.3.2 无法解析 FirebaseRecyclerOptions 的符号<>即使我的应用已成功连接到 Firebase 并正确配置到 Firebase 实时数据库和 FirebaseRecyclerAdaper进口的也很好。

似乎 build.gradle 依赖项已同步且正常。我需要别人的帮助。

下面是我在MainActivities中的依赖和代码。

在 build.gradle 中添加并尝试了其他几个依赖项

private FirebaseRecyclerAdapter<ChatMessage, MessageViewHolder> mFirebaseAdapter; // Ph4 Reading chat

private static final String MESSAGES_CHILD = "messages"; // Ph3 Chat DB

private DatabaseReference mFirebaseDatabaseReference; // Ph3 Chat DB
private EditText mMessageEditText; // Ph3 DB

private FirebaseAuth mFirebaseAuth;
private FirebaseUser mFirebaseUser;

private String mUsername; // Ph3 Chat DB
private String mPhotoUrl; // Ph3 DB

private GoogleApiClient mGoogleApiClient; // Ph2 Log-out

@Override // Ph2 Log-out
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}

public static class MessageViewHolder extends RecyclerView.ViewHolder { // 내부클래스
    TextView nameTextView;
    ImageView messageImageView;
    TextView messageTextView;
    CircleImageView photoImageView;

    public MessageViewHolder(View itemView) {
        super(itemView);

        nameTextView = (TextView) itemView.findViewById(R.id.nameTextView);
        messageImageView = (ImageView) itemView.findViewById(R.id.messageImageView);
        messageTextView = (TextView) itemView.findViewById(R.id.messageTextView);
        photoImageView = (CircleImageView) itemView.findViewById(R.id.photoImageView);
    }
}

private RecyclerView mMessageRecyclerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); // Ph3 Chat DB
    mMessageEditText = (EditText) findViewById(R.id.message_edit); // Ph3 DB

    mMessageRecyclerView = (RecyclerView) findViewById(R.id.message_recycler_view);

    findViewById(R.id.send_button).setOnClickListener(new View.OnClickListener() { // Ph3 Chat DB
        @Override
        public void onClick(View v) {
            ChatMessage chatMessage = new ChatMessage(mMessageEditText.getText().toString(),
                    mUsername, mPhotoUrl, null);
            mFirebaseDatabaseReference.child(MESSAGES_CHILD)
                    .push()
                    .setValue(chatMessage);
            mMessageEditText.setText("");
        }
    });

    mGoogleApiClient = new GoogleApiClient.Builder(this) // Ph2 Log-out
            .enableAutoManage(this, this)
            .addApi(Auth.GOOGLE_SIGN_IN_API)
            .build();

    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseUser = mFirebaseAuth.getCurrentUser();
    if (mFirebaseUser == null) {
        startActivity(new Intent(this, SignInActivity.class));
        finish();
        return;
    } else {
        mUsername = mFirebaseUser.getDisplayName();
        if (mFirebaseUser.getPhotoUrl() != null ) {
            mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
        }
    }

    Query query = mFirebaseDatabaseReference.child(MESSAGES_CHILD); // Ph4 Reading chat
    FirebaseRecyclerOptions<ChatMessage> options = new FirebaseRecyclerOptions.Builder<ChatMessage>() //ph4
            .setQuery(query, ChatMessage.class)
            .build();

    mFirebaseAdapter = new FirebaseRecyclerAdapter<ChatMessage, MessageViewHolder>(options) { // Ph4 Reading chat

        @Override
        protected void onBindViewHolder(MessageViewHolder holder, int position, ChatMessage model) {
            holder.messageTextView.setText(model.getText());
            holder.nameTextView.setText(model.getName());
            if (model.getPhotoUrl() == null) {
                holder.photoImageView.setImageDrawable(ContextCompat.getDrawable(MainActivity.this,
                        R.drawable.ic_account_circle_black_24dp));
            } else {
                Glide.with(MainActivity.this)
                        .load(model.getPhotoUrl())
                        .into(holder.photoImageView);
            }
        }

        @Override
        public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_message, parent, false);
            return new MessageViewHolder(view);
        }

        @Override
        protected void populateViewHolder(MessageViewHolder viewHolder, ChatMessage model, int position) {

        }
    };

    mMessageRecyclerView.setLayoutManager(new LinearLayoutManager(this)); // Ph4
    mMessageRecyclerView.setAdapter(mFirebaseAdapter); // Ph4
}

@Override
protected void onStart() { // Ph4 Reading chat
    super.onStart();
    mFirebaseAdapter.startListening();
}

@Override
protected void onStop() { // Ph4 Reading chat
    super.onStop();
    mFirebaseAdapter.stopListening();
}

@Override // Ph2 Log-out
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override // Ph2 Log-out
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.sign_out_menu:
            mFirebaseAuth.signOut();
            Auth.GoogleSignInApi.signOut(mGoogleApiClient);
            mUsername = "";
            startActivity(new Intent(this, SignInActivity.class));
            finish();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
 }
}
  1. 下面是build.gradle
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.android.support.test:runner:0.5'
    compile 'de.hdodenhof:circleimageview:3.0.0'
    compile 'com.google.firebase:firebase-database:11.0.0'
    compile 'com.google.firebase:firebase-auth:11.0.0'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-auth:11.0.0'

    compile 'com.firebaseui:firebase-ui-database:2.0.0'

    compile 'com.github.bumptech.glide:glide:4.6.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.0'

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

最佳答案

您需要更新您的 FirebaseUI 依赖项,在您的 build.gradle 中使用以下内容:

implementation 'com.firebaseui:firebase-ui-database:4.3.2' 

FirebaseRecyclerOptions 已添加到 Firebaseui 3.0 中,而您使用的是 Firebaseui 2.0,这就是您收到该错误的原因。

更多信息在这里:

https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md


检查以下内容:

Adapter initialization - in previous versions the adapter classes (FirebaseRecyclerAdapter, FirebaseListAdapter, etc) had multiple constructor overloads. In 3.x, each adapter has a single constructor that takes an Options object like FirebaseRecyclerOptions. These options objects can be constructed via their respective builders. For more information, see database/README.md.

https://github.com/firebase/FirebaseUI-Android/blob/master/docs/upgrade-to-3.0.md#realtime-database

注意:

当前最新版本的 FirebaseUI6.4.0:

implementation 'com.firebaseui:firebase-ui-database:6.4.0'

https://github.com/firebase/FirebaseUI-Android

关于java - 无法解析符号 "FirebaseRecyclerOptions",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55429197/

有关java - 无法解析符号 "FirebaseRecyclerOptions"的更多相关文章

  1. Ruby 解析字符串 - 2

    我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?

  2. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  3. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  4. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  5. ruby - 用逗号、双引号和编码解析 csv - 2

    我正在使用ruby​​1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\

  6. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  7. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  8. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  9. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  10. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

随机推荐