【发布时间】:2019-04-13 21:37:33
【问题描述】:
不断收到以下错误:
E/RecyclerView: No adapter attached; skipping layout.
正如您在下面看到的,我设置了适配器,但在 OnDataChange() 方法中我认为这可能是问题,因为它需要在 OnCreate() 方法中,但我似乎无法修复它。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_judge);
RecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
RecyclerView.setHasFixedSize(true);
RecyclerView.setLayoutManager(new LinearLayoutManager(this));
ProgressCircle = findViewById(R.id.progress_circle);
mUploads = new ArrayList<>();
DatabaseRef = FirebaseDatabase.getInstance().getReference("uploads");
DatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
UploadClass upload =
postSnapshot.getValue(UploadClass.class);
mUploads.add(upload);
}
Adapter = new ImageAdapter(JudgeActivity.this, mUploads);
ProgressCircle.setVisibility(View.INVISIBLE);
RecyclerView.setAdapter(Adapter);
}
【问题讨论】:
-
1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) 曾经只需要源代码中的一个空白行。
{之后或}之前的空行通常也是多余的。 3) 使用逻辑一致的形式缩进代码行和块。缩进是为了让代码的流程更容易理解!
标签: java android android-studio android-recyclerview adapter