How do you use copyToRealmOrUpdate for a list?
This is some code in my Android App:
public class Offer extends RealmObject {
@PrimaryKey
private long id;
}
In my service class:
RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
}
I get compile error:
error: incompatible types: bad type in conditional expression
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?
add a comment |
This is some code in my Android App:
public class Offer extends RealmObject {
@PrimaryKey
private long id;
}
In my service class:
RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
}
I get compile error:
error: incompatible types: bad type in conditional expression
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?
add a comment |
This is some code in my Android App:
public class Offer extends RealmObject {
@PrimaryKey
private long id;
}
In my service class:
RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
}
I get compile error:
error: incompatible types: bad type in conditional expression
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?
This is some code in my Android App:
public class Offer extends RealmObject {
@PrimaryKey
private long id;
}
In my service class:
RealmList<Offer> currentLocalMerchantOfferList = currentLocalMerchant.getOffers();
RealmList<Offer> findIncomingMerchantOfferList = findIncomingMerchant.getOffers();
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
}
I get compile error:
error: incompatible types: bad type in conditional expression
currentLocalMerchant.setOffers(findIncomingMerchantOfferList == null ? null : realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
Am I using copyToRealmOrUpdate correctly? If not, how do you use it correctly?
edited Nov 12 at 8:49
asked Nov 12 at 8:36
Alexei
1,10311024
1,10311024
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.
RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.
In fact, they are internally returned as an ArrayList.
The way you can change your code to accomodate is by:
currentLocalMerchant.getOffers().clear();
currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
I need to update items in list in same orders. Is method "addAll()" do this?
– Alexei
Nov 12 at 14:20
I mean, it's justfor(Item item: items) { targetList.add(item) }pretty much
– EpicPandaForce
Nov 12 at 15:12
add a comment |
I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
}
If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.
Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
– Alexei
Nov 12 at 14:18
I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
– Sultan Mahmud
Nov 13 at 8:52
currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
– Alexei
Nov 14 at 9:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258385%2fhow-do-you-use-copytorealmorupdate-for-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.
RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.
In fact, they are internally returned as an ArrayList.
The way you can change your code to accomodate is by:
currentLocalMerchant.getOffers().clear();
currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
I need to update items in list in same orders. Is method "addAll()" do this?
– Alexei
Nov 12 at 14:20
I mean, it's justfor(Item item: items) { targetList.add(item) }pretty much
– EpicPandaForce
Nov 12 at 15:12
add a comment |
realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.
RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.
In fact, they are internally returned as an ArrayList.
The way you can change your code to accomodate is by:
currentLocalMerchant.getOffers().clear();
currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
I need to update items in list in same orders. Is method "addAll()" do this?
– Alexei
Nov 12 at 14:20
I mean, it's justfor(Item item: items) { targetList.add(item) }pretty much
– EpicPandaForce
Nov 12 at 15:12
add a comment |
realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.
RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.
In fact, they are internally returned as an ArrayList.
The way you can change your code to accomodate is by:
currentLocalMerchant.getOffers().clear();
currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
realm.copyToRealmOrUpdate(findIncomingMerchantOfferList) returns a List<T> and not a RealmList<T>.
RealmList represents many-relationship to another object type. Therefore, these randomly inserted objects aren't a many-relationship, therefore they are not RealmList.
In fact, they are internally returned as an ArrayList.
The way you can change your code to accomodate is by:
currentLocalMerchant.getOffers().clear();
currentLocalMerchant.getOffers().addAll(realm.copyToRealmOrUpdate(findIncomingMerchantOfferList));
answered Nov 12 at 9:55
EpicPandaForce
47.1k14126246
47.1k14126246
I need to update items in list in same orders. Is method "addAll()" do this?
– Alexei
Nov 12 at 14:20
I mean, it's justfor(Item item: items) { targetList.add(item) }pretty much
– EpicPandaForce
Nov 12 at 15:12
add a comment |
I need to update items in list in same orders. Is method "addAll()" do this?
– Alexei
Nov 12 at 14:20
I mean, it's justfor(Item item: items) { targetList.add(item) }pretty much
– EpicPandaForce
Nov 12 at 15:12
I need to update items in list in same orders. Is method "addAll()" do this?
– Alexei
Nov 12 at 14:20
I need to update items in list in same orders. Is method "addAll()" do this?
– Alexei
Nov 12 at 14:20
I mean, it's just
for(Item item: items) { targetList.add(item) } pretty much– EpicPandaForce
Nov 12 at 15:12
I mean, it's just
for(Item item: items) { targetList.add(item) } pretty much– EpicPandaForce
Nov 12 at 15:12
add a comment |
I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
}
If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.
Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
– Alexei
Nov 12 at 14:18
I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
– Sultan Mahmud
Nov 13 at 8:52
currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
– Alexei
Nov 14 at 9:05
add a comment |
I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
}
If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.
Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
– Alexei
Nov 12 at 14:18
I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
– Sultan Mahmud
Nov 13 at 8:52
currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
– Alexei
Nov 14 at 9:05
add a comment |
I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
}
If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.
I think you don't need to use copyToRealmOrUpdate method to set value. Just set the value that you have
if (!EqualsUtil.areEqual(currentLocalMerchantOfferList, findIncomingMerchantOfferList)) {
currentLocalMerchant.setOffers(findIncomingMerchantOfferList)
}
If findIncomingMerchant.getOffers() back to you persistent data than it will work perfectly.
answered Nov 12 at 9:23
Sultan Mahmud
23017
23017
Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
– Alexei
Nov 12 at 14:18
I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
– Sultan Mahmud
Nov 13 at 8:52
currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
– Alexei
Nov 14 at 9:05
add a comment |
Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
– Alexei
Nov 12 at 14:18
I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
– Sultan Mahmud
Nov 13 at 8:52
currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
– Alexei
Nov 14 at 9:05
Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
– Alexei
Nov 12 at 14:18
Not work. I get error: java.lang.IllegalArgumentException: 'value' is not a valid managed object.
– Alexei
Nov 12 at 14:18
I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
– Sultan Mahmud
Nov 13 at 8:52
I already mentioned that you can add only persistent to persistent data. I think you don't understand my point. Apply this currentLocalMerchant.setOffers(realm.copyfromRealm(findIncomingMerchantOfferList))
– Sultan Mahmud
Nov 13 at 8:52
currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
– Alexei
Nov 14 at 9:05
currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList)); But I geterror: incompatible types: no instance(s) of type variable(s) E exist so that List<E> conforms to RealmList<Offer> currentLocalMerchant.setOffers(realm.copyToRealm(findIncomingMerchantOfferList));
– Alexei
Nov 14 at 9:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258385%2fhow-do-you-use-copytorealmorupdate-for-a-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown