Olá pessoal, estou aprendendo a programar para android e estou criando um app simples.
Ele roda e no editor nada indica erro. Mas no emulador mostra apenas a Toolbar e o resto
da tela em branco. Sinto que estou cometendo um erro muito amador, agradeço a ajuda.
No “Run” apresenta o erro:
E/RecyclerView: No adapter attached; skipping layout
E/RecyclerView: No adapter attached; skipping layout
BooksActivity
package com.example.nybooks.presentation.books
import android.arch.lifecycle.Observer
//import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProviders
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import com.example.nybooks.R
import com.example.nybooks.presentation.books.presentation.details.BookDetailsActivity
//import data.model.Book
import kotlinx.android.synthetic.main.activity_books.*class BooksActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_books) toolbarMain.title = getString(R.string.books_title) setSupportActionBar(toolbarMain) val viewModel: BooksViewModel = ViewModelProviders.of(this).get(BooksViewModel::class.java) viewModel.booksLiveData.observe(this, Observer { it?.let { books -> with(recycleBooks) { layoutManager = LinearLayoutManager(this@BooksActivity, RecyclerView.VERTICAL, false) setHasFixedSize(true) adapter = BooksAdapter(books) { book -> val intent = BookDetailsActivity.getStartIntent(this@BooksActivity, book.title, book.description) this@BooksActivity.startActivity(intent) } } } }) viewModel.getBooks() }
}
activity_books.xml
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".presentation.books.BooksActivity"><android.support.v7.widget.Toolbar android:id="@+id/toolbarMain" android:layout_width="0dp" android:layout_height="?android:attr/actionBarSize" android:background="@color/colorPrimary" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> <android.support.v7.widget.RecyclerView android:id="@+id/recycleBooks" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/toolbarMain" tools:listitem="@layout/item_book"/>
</android.support.constraint.ConstraintLayout>