Comments (13)
@Zhuinden You were quite right - turning off the animation did the trick. I've updated the source code above to show the original instantiation of the adapter with animation = true.
Why the crash shows
columnIndex is less than 0
instead of
Animating the results requires a primaryKey
Is really very odd - and a likely defect.
The question why animation needs a primary key is a odd but separate question.
from realm-recyclerview.
Do you have a @PrimaryKey
?
from realm-recyclerview.
@matbrandao Could you add a stacktrace?
from realm-recyclerview.
I had the same problem when I tried to query from realmObject by findAll()
RealmResults<Alarm> alarms = realm
.where(Alarm.class)
.findAll();
I don't know if it's a same problem, but I resolved it by using findAllSorted() instead of findAll()
from realm-recyclerview.
I'm getting this error now. My realm class doesn't have a PrimaryKey, as it's a child in a parent / child relationship. I want to get all of the items that belong to the parent and show them.
According to Realm developer (although this is for an iOS answer), PrimaryKey's aren't needed. https://stackoverflow.com/questions/32322460/should-i-define-the-primary-key-for-each-entity-in-realm
Extrapolating the above comment from @Zhuinden , does this mean it is required for realm-recyclerview?
from realm-recyclerview.
@b12kab technically primary keys shouldn't be necessary, and findAll()
should work just fine. I got a similar error back a long day ago when I tried setting a RealmList that hadn't been copied to the Realm, but that was a while ago.
I'd have to know the code, really. A complete stack trace would be useful too, and Realm version.
EDIT: oh wait, this is the thorbenprimke realm RecyclerView.
Yes, you should have a string or long primary key to use this library with your RealmObject.
from realm-recyclerview.
Just in case @thorbenprimke might want it.
public class RealmReview extends RealmObject {
@Index
int parentId;
String id;
String author;
String content;
String url;
Date dateAdded;
Date dateUpdated;
}
Calling the Adapter:
mAdapter = new AdapterRecyclerViewRealmMovieReviews(mContext, mMovieResults, true, true);
Adapter:
public class AdapterRecyclerViewRealmReview extends RealmBasedRecyclerViewAdapter<RealmReview,
AdapterRecyclerViewRealmReview.ViewReviewHolder> {
private Context mContext = null;
public AdapterRecyclerViewRealmReview (
Context context, RealmResults<RealmReview> realmResults,
boolean automaticUpdate, boolean animateIdType) {
super(context, realmResults, automaticUpdate, animateIdType);
resetContext(context);
}
<stuff>
void resetContext(Context context) {
if (context != null) {
mContext = context;
}
}
}
Crash
--------- beginning of crash
07-23 18:46:21.663 8822-8822/net.springtale.realmviewholderexperiment E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.springtale.realmviewholderexperiment, PID: 8822
java.lang.ArrayIndexOutOfBoundsException: columnIndex is less than 0.
at io.realm.internal.TableView.nativeGetColumnType(Native Method)
at io.realm.internal.TableView.getColumnType(TableView.java:173)
at io.realm.RealmBasedRecyclerViewAdapter.<init>(RealmBasedRecyclerViewAdapter.java:172)
at io.realm.RealmBasedRecyclerViewAdapter.<init>(RealmBasedRecyclerViewAdapter.java:133)
at io.realm.RealmBasedRecyclerViewAdapter.<init>(RealmBasedRecyclerViewAdapter.java:123)
at net.springtale.realmviewholderexperiment.AdapterRecyclerViewRealmReview.<init>(AdapterRecyclerViewRealmReview.java:29)
at net.springtale.realmviewholderexperiment.FragmentMovieDetailReviews.fixAdapter(FragmentMovieDetailReviews.java:222)
at net.springtale.realmviewholderexperiment.FragmentMovieDetailReviews.resetMovieIdDetails(FragmentMovieDetailReviews.java:280)
at net.springtale.realmviewholderexperiment.FragmentMovieDetailReviews.onCreateView(FragmentMovieDetailReviews.java:175)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1632)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:637)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1235)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1083)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1609)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:1878
from realm-recyclerview.
Well if you look at the source, you are crashing on this line
Which is
this.animateResults = (automaticUpdate && animateResults);
if (animateResults) {
animatePrimaryColumnIndex = realmResults.getTable().getTable().getPrimaryKey();
if (animatePrimaryColumnIndex == TableOrView.NO_MATCH) {
throw new IllegalStateException(
"Animating the results requires a primaryKey.");
}
animatePrimaryIdType = realmResults.getTable().getColumnType(animatePrimaryColumnIndex);
So you are trying to animate your results, but you don't have enough a primary key.
You can fix this by changing id to be primary key, or by disabling animating results.
from realm-recyclerview.
@b12kab reading the source of Table, it quite obviously returns -2
specified as NO_PRIMARY_KEY
, but the condition here is for NO_MATCH
which is -1
.
By the way, the PK is required to match the two retained results against one another and determine what element changed from where to where, and to identify the elements (to determine where they moved), their ID is required.
from realm-recyclerview.
Your id
field in your RealmObject though, why isn't it a primary key?
from realm-recyclerview.
In my current use, I don't care what the id value is - I'm only using the parentId (1 to n objects with the same parentId). I'm not positive that the review id is always unique, so I don't want to take a chance with a duplicated primary key using the id field.
In this particular case, I don't actually need that animation functionality.
from realm-recyclerview.
I see, that makes sense. If it is not guaranteed to be unique, then it shouldn't be a primary key!
anyways, I think we've solved the case :)
from realm-recyclerview.
from realm-recyclerview.
Related Issues (20)
- How can we get the LayoutManager? HOT 2
- Enable swipe to delete only in one direction?
- Need to draw background with an icon when the user swipes an item
- Fatal signal 11 while deleting object from Realm
- How to scroll to position not softly?
- how to fire loadmore after fetching and showing every 100 records from realm HOT 1
- Issues When Having Multiple View Types HOT 1
- Attempting to use Realm-recyclerview with Object Server.... HOT 4
- Size APK HOT 1
- Is it possible to animate RealmRecycleView when i change sort directional?
- example app ArrayIndexOutOfBoundsException: rowIndex > available rows: 2 > 2
- Realm recycler view not refreshing on first insert HOT 1
- How to Make Recycler View show rows from bottom HOT 1
- java.lang.NullPointerException null object reference in Fragment
- Can I group by any field? HOT 1
- Please update to Realm Java 3.0.0
- Can't create a RealmRecycleView Programmatically
- Realm Recyclerview not working with Realm 3.5.0 HOT 1
- Error:(39, 14) Failed to resolve: com.github.thorbenprimke:realm-recyclerview:0.9.25 HOT 1
- Doesn't work with android studio 3.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from realm-recyclerview.