无法解析符号'FirebaseRecyclerOptions<>'



我正在通过firebase制作费用管理器,但我的Android Studio 2021.3无法解析FirebaseRecyclerOptions<>甚至我的应用程序也成功地连接到Firebase并正确配置为Firebase实时数据库。

似乎构建。gradle依赖项被同步并且OK。我需要别人的帮助。

package com.example.budgetingapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import org.joda.time.DateTime;
import org.joda.time.Months;
import org.joda.time.MutableDateTime;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.zip.DataFormatException;
public class BudgetActivity extends AppCompatActivity {
private TextView totalBudgetAmountTextView;
private RecyclerView recyclerView;
private FloatingActionButton fab;
private DatabaseReference budgetRef;
private FirebaseAuth mAuth;
private ProgressDialog loader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_budget);
mAuth = FirebaseAuth.getInstance();
budgetRef = FirebaseDatabase.getInstance().getReference().child("budget").child(mAuth.getCurrentUser().getUid());
loader = new ProgressDialog(this);
totalBudgetAmountTextView = findViewById(R.id.totalBudgetAmountTextView);
recyclerView = findViewById(R.id.recyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setStackFromEnd(true);
linearLayoutManager.setReverseLayout(true);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(linearLayoutManager);
fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
additem();
}
});
}
private void additem() {
AlertDialog.Builder myDialog = new AlertDialog.Builder(this);
LayoutInflater inflater = LayoutInflater.from(this);
View myView = inflater.inflate(R.layout.input_layout,null);
myDialog.setView(myView);
final AlertDialog dialog =  myDialog.create();
dialog.setCancelable(false);
final Spinner itemSpinner = myView.findViewById(R.id.itemSpinner);
final EditText amount = myView.findViewById(R.id.amount);
final Button cancel = myView.findViewById(R.id.cancel);
final  Button save = myView.findViewById(R.id.save);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String budgetAmount = amount.getText().toString();
String budgetItem = itemSpinner.getSelectedItem().toString();
if(TextUtils.isEmpty(budgetAmount)){
amount.setError("Amount is required!");
return;
}
if(budgetItem.equals("Select Item")){
Toast.makeText(BudgetActivity.this, "Select a valid item", Toast.LENGTH_SHORT).show();
}else{
loader.setMessage("adding a budget item");
loader.setCanceledOnTouchOutside(false);
loader.show();
String id = budgetRef.push().getKey();
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Calendar cal = Calendar.getInstance();
String date = dateFormat.format(cal.getTime());
MutableDateTime epoch= new MutableDateTime();
epoch.setDate(0);
DateTime now = new DateTime();
Months months = Months.monthsBetween(epoch,now);
Data data = new Data(budgetItem,date,id,null,Integer.parseInt(budgetAmount),months.getMonths());
budgetRef.child(id).setValue(data).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(BudgetActivity.this, "Budget item added successfully.", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(BudgetActivity.this, task.getException().toString(), Toast.LENGTH_SHORT).show();
}
loader.dismiss();
}
});
}
dialog.dismiss();
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});

dialog.show();
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<Data> options = new FirebaseRecyclerOptions.Builder<Data>()
.setQuery(budgetRef, Data.class)
.build();
}
}
  1. 下面是build.gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.firebase:firebase-auth:21.1.0'
implementation 'com.google.firebase:firebase-database:20.1.0'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
implementation platform('com.google.firebase:firebase-bom:31.1.1')
implementation 'com.google.firebase:firebase-analytics'
implementation 'joda-time:joda-time:2.10.6'
implementation 'com.firebaseui:firebase-ui-database:6.4.0'
}

您还没有将任何FirebaseUI类导入到Java文件中,因此无法找到它们。

要能够使用FirebaseRecyclerOptions,包括:

import com.firebase.ui.database.FirebaseRecyclerOptions;

您需要对您使用的FirebaseUI中的其他类做相同的操作。

相关内容

  • 没有找到相关文章

最新更新