Я получаю ошибку в mRecyclerView.setLayoutManager(layoutManager);
Ниже приведена ошибка logcat, появляющаяся при входе в действие:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference at com.example.lenovo.skanda.QuoteList.onCreate(QuoteList.java:36)
QuoteList.java
public class QuoteList extends AppCompatActivity {
private StorageReference storageRef;
RecyclerView mRecyclerView;
FirebaseDatabase mFirebaseDatabase;
DatabaseReference mReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quote_list);
//ActionBar actionBar = getSupportActionBar();
//getSupportActionBar().setTitle("Quotes");
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//getSupportActionBar().setHomeButtonEnabled(true);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView = findViewById(R.id.recyclerViewQuote);
// mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mFirebaseDatabase = FirebaseDatabase.getInstance();
mReference = mFirebaseDatabase.getReference("Quotes");
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Quote, QuoteViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<Quote, QuoteViewHolder>(
Quote.class,
R.layout.quote_row,
QuoteViewHolder.class,
mReference
) {
@Override
protected void populateViewHolder(QuoteViewHolder viewHolder , Quote model , int position) {
// viewHolder.setDetails(getApplicationContext(), model.getQuotes(), model.getQuote_Author(), model.getImages());
viewHolder.setQuotes(model.getQuotes());
viewHolder.setQuoteAuthor(model.getQuote_Author());
}
};
mRecyclerView.setAdapter(firebaseRecyclerAdapter);
}
public static class QuoteViewHolder extends RecyclerView.ViewHolder{
View mView;
public QuoteViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setQuotes(String Quote){
TextView post_quote = (TextView) mView.findViewById(R.id.post_quote);
post_quote.setText(Quote);
}
public void setQuoteAuthor(String QuoteAuthor){
TextView post_quoteAuthor = (TextView) mView.findViewById(R.id.post_author);
post_quoteAuthor.setText(QuoteAuthor);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
}
Пожалуйста, помогите мне.
Удалите ниже Код: final LinearLayoutManager layoutManager = new LinearLayoutManager (this); layoutManager.setOrientation (LinearLayoutManager.VERTICAL); mRecyclerView.setLayoutManager (layoutManager);




Ваш RecyclerView еще не назначен, поменяйте местами:
mRecyclerView = findViewById(R.id.recyclerViewQuote);
mRecyclerView.setLayoutManager(layoutManager);
Пожалуйста, напишите такой код, вам сначала нужно инициализировать recyclerview перед Linear Layout Manager.
mRecyclerView = findViewById(R.id.recyclerViewQuote);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(layoutManager);
Спасибо, дружище .. Большое спасибо за помощь :)
Самый добро пожаловать, Пратик
Можете ли вы решить эту проблему. ссылка
Это происходит, когда LinearLayout не может найти RecyclerView в вашем макете.
Вы должны добавить RecyclerView в свой файл макета, где будут отображаться списки,
или же созданный RecyclerView был ошибочно упомянут, когда не упоминалось использование findViewById(R.id.recyclerviewID) или RecyclerView.
Вы устанавливаете Диспетчер макетов два раза. Я думаю, это причина показывает ошибку