gpt4 book ai didi

android - 尝试从 Firestore 加载时应用关闭

转载 作者:搜寻专家 更新时间:2023-11-01 09:24:01 30 4
gpt4 key购买 nike

我正在尝试从 firestore 数据库中检索数据,但每次我运行该方法时,应用程序都会崩溃。我查看了 logcat 调试器,但不确定它的全部含义。

如果我注释方法 getAssessList(),布局加载和所有。但是如果没有注释,应用程序就会崩溃,所以我假设问题就出在这里。

这是 Activity 代码:

package com.version.crt.markbuddy;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.Query;
import com.version.crt.markbuddy.model.Assessment;
import butterknife.BindView;
import butterknife.ButterKnife;

public class EditImportActivity extends AppCompatActivity {

int selected_position = RecyclerView.NO_POSITION;

@BindView(R.id.progress_bar)
ProgressBar progressBar;

@BindView(R.id.friend_list)
RecyclerView friendList;

@BindView(R.id.txt1)
TextView txt1;

@BindView(R.id.btn1)
Button btn1;


private FirebaseFirestore db;
private FirestoreRecyclerAdapter adapter;
LinearLayoutManager linearLayoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_import);
ButterKnife.bind(this);
init();
getAsessList();
}

private void init(){
linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
friendList.setLayoutManager(linearLayoutManager);
db = FirebaseFirestore.getInstance();
}

private void getAsessList(){
Query query = db.collection("test");

FirestoreRecyclerOptions<Assessment> response = new FirestoreRecyclerOptions.Builder<Assessment>()
.setQuery(query, Assessment.class)
.build();

adapter = new FirestoreRecyclerAdapter<Assessment, AssHolder> (response) {
@Override
public void onBindViewHolder(AssHolder holder, int position, Assessment model) {
progressBar.setVisibility(View.GONE);
holder.textView_title.setText(model.getDesc());
holder.textView_date.setText(model.getDate());
holder.textView_time.setText(model.getTime());
holder.textView_weighting.setText(model.getWeight());

if (selected_position == position) {

holder.itemView.setBackgroundColor(Color.BLUE);
} else {
holder.itemView.setBackgroundColor(Color.GREEN);
}


holder.itemView.setOnClickListener(v -> {
if (position == RecyclerView.NO_POSITION) return;
txt1.setText(model.getDesc());
// Updating old as well as new positions

notifyItemChanged(selected_position);
selected_position = position;
notifyItemChanged(selected_position);

Snackbar.make(friendList, "", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
});


}

@NonNull
@Override
public AssHolder onCreateViewHolder(@NonNull ViewGroup group, int i) {
View view = LayoutInflater.from(group.getContext())
.inflate(R.layout.item_tape1, group, false);

return new AssHolder(view);
}

@Override
public void onError(FirebaseFirestoreException e) {
Log.e("error", e.getMessage());
}
};

adapter.notifyDataSetChanged();
friendList.setAdapter(adapter);
}

public class AssHolder extends RecyclerView.ViewHolder {
@BindView(R.id.textView_title)
TextView textView_title;
@BindView(R.id.textView_date)
TextView textView_date;
@BindView(R.id.textView_time)
TextView textView_time;
@BindView(R.id.textView_weighting)
TextView textView_weighting;

AssHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}

@Override
public void onStart() {
super.onStart();
//adapter.startListening();
}

@Override
public void onStop() {
super.onStop();
adapter.stopListening();
}
}

和调试日志:

debug

我错过了什么或做错了什么

成绩模块:应用

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
defaultConfig {
applicationId "com.version.crt.markbuddy"
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:support-v13:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.2'
implementation 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'

//anko
implementation "org.jetbrains.anko:anko:$anko_version"
implementation "org.jetbrains.anko:anko-design:$anko_version"
implementation "org.jetbrains.anko:anko-coroutines:$anko_version"
//firebase
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-firestore:17.1.0'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.firebaseui:firebase-ui-auth:4.0.0'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-storage:3.3.1'
implementation 'com.google.android.gms:play-services-auth:16.0.0'
implementation 'com.google.firebase:firebase-messaging:17.3.0'

//glide
implementation 'com.github.bumptech.glide:glide:4.6.1'
kapt 'com.github.bumptech.glide:compiler:4.6.1'
//groupie
implementation 'com.xwray:groupie:2.0.3'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.0.3'

implementation 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.firebaseui:firebase-ui-firestore:3.3.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'

//kotlin annotation processor
kotlin {

experimental {

coroutines "enable"

}

}
androidExtensions {

experimental = true

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

项目:马克哥们

buildscript {
ext.kotlin_version = '1.2.60'
ext.anko_version='0.10.4'
repositories {
google()
jcenter()
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.0'
}
}

allprojects {
repositories {
google()
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

最佳答案

根据有关 Firebase-UI 的官方文档库,要解决这个问题,请更改以下代码行:

implementation 'com.firebaseui:firebase-ui-auth:4.0.0'
implementation 'com.firebaseui:firebase-ui-storage:3.3.1'
implementation 'com.firebaseui:firebase-ui-firestore:3.3.1'

implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
implementation 'com.firebaseui:firebase-ui-storage:4.1.0'
implementation 'com.firebaseui:firebase-ui-firestore:4.1.0'

还有:

classpath 'com.google.gms:google-services:4.0.0'

classpath 'com.google.gms:google-services:4.1.0'

关于android - 尝试从 Firestore 加载时应用关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52169812/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com