我对该程序进行了编码,将ArrayList
发送到回收站视图适配器,并显示了该程序,但出现错误。有人可以告诉我原因吗?
谢谢
我的控制台日志:
FATAL EXCEPTION: main
Process: com.shgattendanceapp, PID: 6524
java.lang.NoSuchMethodError: No virtual method zzNU()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.shgattendanceapp-2/split_lib_dependencies_apk.apk)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.shgattendanceapp.NamesActivity.onCreate(NamesActivity.java:32)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
我的名字活动:
public class NamesActivity extends AppCompatActivity {
RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_names);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("5225");
final ArrayList<String> nameslistfinal = new ArrayList<String>();
recyclerView = findViewById(R.id.rv_list);
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
DataSnapshot nameslist = dataSnapshot.child("Members");
Iterable<DataSnapshot> names = nameslist.getChildren();
for (DataSnapshot value : names) {
String c = (String) value.getValue();
nameslistfinal.add(c);
}
recyclerView.setAdapter(new RvAdapter1(nameslistfinal));
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
System.out.println("Failed to read value." + error.toException());
}
});
}
}
我的适配器:
public class RvAdapter1 extends RecyclerView.Adapter<RvAdapter1.ViewHolder> {
private ArrayList<String> values;
RvAdapter1(ArrayList<String> values) {
this.values = values;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_names,parent,false));
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.name.setText(values.get(position));
}
@Override
public int getItemCount() {
return values.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
private TextView name;
ViewHolder(View itemView) {
super(itemView);
name = (TextView) itemView.findViewById(R.id.list_items);
}
}
我的依赖项:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.shgattendanceapp"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
} }
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
//noinspection GradleCompatible
compile 'com.google.firebase:firebase-core:16.0.0'
compile "com.google.firebase:firebase-auth:9.0.0"
compile 'com.google.firebase:firebase-database:9.0.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
}
apply plugin: 'com.google.gms.google-services'