I did follow Youtube tutorial on how to retrieve data from Firebase Cloud Firestore at part 3. Here is the link Part3 .
(我没有按照有关如何在部分3.这里检索火力地堡云公司的FireStore数据的Youtube教程链接第三部分 。)
I changed a bit of code, from main to go to the class that will print the result of data I retrieve from Firebase, but suddenly when i try clicked button to go to the next activity it shows this error. (我从main更改了一些代码,转到将打印从Firebase检索到的数据结果的类,但是突然间,当我尝试单击按钮转到下一个活动时,它显示此错误。)
2019-12-01 20:18:34.015 5780-5780/com.example.testingchat E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.testingchat, PID: 5780
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/firestore/QueryListenOptions;
at com.firebase.ui.firestore.FirestoreRecyclerOptions$Builder.setQuery(FirestoreRecyclerOptions.java:108)
at com.example.testingchat.ForumTitle.setUpRecyclerView(ForumTitle.java:45)
at com.example.testingchat.ForumTitle.onCreate(ForumTitle.java:37)
at android.app.Activity.performCreate(Activity.java:7009)
This is my gradle
(这是我的摇篮)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.testingchat"
minSdkVersion 15
multiDexEnabled true
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation "com.firebaseui:firebase-ui-firestore:3.0.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:21.3.0'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
MainActivity.java
(MainActivity.java)
public class MainActivity extends AppCompatActivity {
private static final String TAG = "FireLog";
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,ForumTitle.class);
startActivity(intent);
}
});
}
}
UserAdapter.java
(UserAdapter.java)
public class UserAdapter extends FirestoreRecyclerAdapter <Userz,UserAdapter.UserHolder>{
/**
* Create a new RecyclerView adapter that listens to a Firestore Query. See
* {@link FirestoreRecyclerOptions} for configuration options.
*
* @param options
*/
public UserAdapter(FirestoreRecyclerOptions<Userz> options) {
super(options);
}
@Override
protected void onBindViewHolder(UserHolder userHolder, int i, Userz userz) {
userHolder.textViewName.setText(userz.getName());
userHolder.textViewStatus.setText(userz.getStatus());
userHolder.textViewMessage.setText(userz.getMessages());
}
@NonNull
@Override
public UserHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview,parent,false);
return new UserHolder(v);
}
class UserHolder extends RecyclerView.ViewHolder{
TextView textViewName;
TextView textViewMessage;
TextView textViewStatus;
public UserHolder(View itemView) {
super(itemView);
textViewName = itemView.findViewById(R.id.name);
textViewMessage = itemView.findViewById(R.id.messages);
textViewStatus = itemView.findViewById(R.id.status);
}
}
}
ForumTitle.java
(ForumTitle.java)
public class ForumTitle extends AppCompatActivity {
private FirebaseFirestore db = FirebaseFirestore.getInstance();
private CollectionReference userRef = db.collection("Users");
private UserAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forum_title);
setUpRecyclerView();
}
private void setUpRecyclerView(){
Query query = userRef.orderBy("name",Query.Direction.DESCENDING);
FirestoreRecyclerOptions<Userz> options = new FirestoreRecyclerOptions.Builder<Userz>()
.setQuery(query,Userz.class)
.build();
adapter = new UserAdapter(options);
RecyclerView recyclerView = findViewById(R.id.my_recycler_view);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
}
@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}
}
ask by MUHAMAD NUR FIKRY BIN MARJAMAL translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…