App crashing when trying to use RecyclerView on android 5.0
This issue usually occurs when no LayoutManager
was provided for the RecyclerView
. You can do it like so:
final LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
Why does my activity crash when trying to search recycler view?
Figured out how to fix error by another video and it is pretty much just a more simple Filter rewrite
Where I populate my recycler view all I did was add this
while ((nyseLine = nyseReader.readNext()) != null){
nyseSymbol = nyseLine[0];
nyseFullName = nyseLine[1];
stocksList.add(new StocksList(nyseSymbol, "", nyseFullName, null));
}
//I added this to set the adapter and show the list immediately after
//loading
adapter = new StocksListAdapter(stocksList);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
Then I crated this method in The SAME activity not in the adapter class
private void Filter(String searched) {
for (StocksList stock : stocksList ){
if (stock.getSymbol().toLowerCase().equals(searched)){
//created new array list for the filter
filteredList.add(stock);
}
}
recyclerView.setAdapter(new StocksListAdapter(filteredList));
adapter.notifyDataSetChanged();
}
And this is the OnCreate class editText listener
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
searchStocks.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
//Moved the the stuff to afterTextChanged not onTextChanged
@Override
public void afterTextChanged(Editable editable) {
filteredList.clear();
if (editable.toString().isEmpty()){
recyclerView.setAdapter(new StocksListAdapter(stocksList));
adapter.notifyDataSetChanged();
} else {
Filter(editable.toString());
}
}
});
I'm pretty sure the error was the fact that I set all the recycler view values like recyclerview.setAdapter(new StocksListAdapter(stocksList)
in one method that I called once in the oncreate method
And when it needed to update the adapter with a new filtered list adapter.notifyDataSetChanged()
was unreachable and didn't do anything.
And so inside the adapter class it was working with inconsistent lists back and forth thus crashing. This is only my guess though, and the comment from @shagberg really helped.
P.S anyone else having this problem in the future: check your notifyDataSetChanged()
calls so they aren't after Filter
calls or other data changing methods because if it's called in the wrong place it crashes.
RecyclerView crashes the application
Change
recView.findViewById(R.id.recView);
to
recView = findViewById(R.id.recView);
Also you have duplicated:
setContentView(R.layout.activity_main);
You have to set the contentView before you try to find the views.
App crashing when trying to use RecyclerView With LayoutManager
As you mentioned you are using two reyclerView
so please check your recyclerview Id
is it there perfect recyclerview id
or you are assign same id
for both of the recyclerview
.
Reference Code :
Reference : https://www.androidhive.info/2016/01/android-working-with-recycler-view/
call prepareToDOData();
inside setAdapters()
private void setAdapters() {
todosAdapter = new TodosAdapter(toDoList);
RecyclerView.LayoutManager mLayoutManager1 = new LinearLayoutManager(getApplicationContext());
rvTodos.setLayoutManager(mLayoutManager1);
rvTodos.setItemAnimator(new DefaultItemAnimator());
rvTodos.setAdapter(todosAdapter);
prepareToDOData();//call here
}
private void prepareToDOData() {
ToDo data = new ToDo("David Cummings", "26/10/2017 2:25PM");
toDoList.add(data);
data = new ToDo("Lawrence Cummings", "26/10/2017 2:25PM");
toDoList.add(data);
data = new ToDo("Ketul Inc.", "11/11/2017 3:46 PM");
toDoList.add(data);
//notesAdapter.notifyDataSetChanged();
todosAdapter.notifyDataSetChanged();
}
Firestore RecyclerView app's crashing when run
You need to update firebase dependencies to latest one. Add below lines to app level gradle. Remove all the version codes from all the dependencies as below -
You can follow the link Firebase
implementation platform('com.google.firebase:firebase-bom:28.3.1')
// When using the BoM, you don't specify versions in Firebase library
//dependencies
// Declare the dependency for the Firebase SDK for Google Analytics
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-storage'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.firebaseui:firebase-ui-firestore'
implementation 'com.google.firebase:firebase-analytics'
Android RecyclerView crashing when loaded
You have to set a LayoutManager for the RecyclerView. For example, for a vertical scroll list, you should use LinearLayoutManager like this.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_drawer);
recyclerView = findViewById(R.id.appsList);
// add this
recyclerView.setLayoutManager(new LinearLayoutManager(this));
AppAdapter adapter = new AppAdapter(this);
// replace this line by this two. (you should not call adapter method directly).
// adapter.onCreateViewHolder(recyclerView, 0); // LINE 23
recyclerView.setAdapter(adapter);
// notify the adapter that the data has changed
recyclerView.notifyDataSetChanged();
}
App crashes when using RecyclerView
This problem caused when android start dealing with bitmaps.
the main reason is lack of memory space and also, garbage collector cannot free some space.
You have two solutions for this situation:
- largeHeap
Go to your manifest file and add
android:largeHeap="true"
android:hardwareAccelerated="false"
inside application tag for example
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:largeHeap="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
- Using library like Universal Image Loader
https://github.com/nostra13/Android-Universal-Image-Loader
Related Topics
Android - Save Image from Url Onto Sd Card
I Cant See Any Firebaserecycleradapter Items on My Layout
How to Move/Rename File from Internal App Storage to External Storage on Android
Attempt to Re-Open an Already-Closed Object: SQLitedatabase
Sqliteopenhelper Failing to Call Oncreate
Get Button Coordinates and Detect If Finger Is Over Them - Android
Integration Testing Frameworks for Testing a Distributed System
How to Convert Camelcase into Human-Readable Names in Java
Multiple Dex Files Define Landroid/Support/Annotation/Animres
Google Maps API and Custom Polyline Route Between Markers
App Crashing When Trying to Use Recyclerview on Android 5.0
Android Runtime Permissions- How to Implement
Android 3.1 Usb-Host - Broadcastreceiver Does Not Receive Usb_Device_Attached