无法解析符号"FirebaseRecyclerOptions"



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

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

以下是我在 MainActivity 中的依赖关系和代码。

在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

<小时 />

检查以下内容:

适配器初始化 - 在以前的版本中,适配器类(FirebaseRecyclerAdapterFirebaseListAdapter等(有多个构造函数重载。在 3.x 中,每个适配器都有一个构造函数,该构造函数采用 Options 对象,如 FirebaseRecyclerOptions 。这些选项对象可以通过其各自的生成器构造。有关详细信息,请参阅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

相关内容

  • 没有找到相关文章

最新更新