每次我运行此活动时,我的应用都会由于某种原因而崩溃。正如我在调试模式下所发现的那样,问题似乎出在onStart
方法上。
public class TimesListActivity extends AppCompatActivity {
private ListView listView;
DatabaseReference mDatabaseReference;
List<Message>messageList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_times_list);
listView = findViewById(R.id.list_view);
mDatabaseReference = FirebaseDatabase.getInstance().getReference("messages");
messageList = new ArrayList<Message>();
}
@Override
protected void onStart() {
super.onStart();
mDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot mDataSnapshot : dataSnapshot.getChildren()) {
Message message = mDataSnapshot.getValue(Message.class);
messageList.add(message);
}
TimeMessageAdapter messageAdapter = new TimeMessageAdapter(TimesListActivity.this, messageList);
listView.setAdapter(messageAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
执行活动时,崩溃日志将打印出以下内容
com.google.firebase.database.DatabaseException: Class com.example.[username].[app name].Message does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.