Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want to store an array of strings in Realm #5701

Closed
FahdSaif opened this issue Jan 19, 2018 · 5 comments
Closed

I want to store an array of strings in Realm #5701

FahdSaif opened this issue Jan 19, 2018 · 5 comments
Labels

Comments

@FahdSaif
Copy link

Hi,

I am wanting to store an array of strings in realm through my object.Although I am new to realm but i have read through the documentation completely and also tried out samples. Here is my example model.From what i have gathered so far on stackoverflow that this is not possible to store an array of strings inside an object we are putting in realm? Is my understanding and findings correct?

package com.example.fahdsaif.realmtest;

import java.util.ArrayList;
import java.util.List;

import io.realm.RealmObject;

/**

  • Created by fahdsaif on 17/1/18.
    */

public class RealmModel extends RealmObject {
private String firstName;
private String lastName;
private String meraarray[] = new String[10];

public String[] getMeraarray() {
    return meraarray;
}

public void setMeraarray(String[] meraarray) {
    this.meraarray = meraarray;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

}

and here is the realm code for inserting into this model:

some code then...

myrealm.executeTransactionAsync(new Realm.Transaction() {
@OverRide
public void execute(Realm bgrealm) {
RealmModel myrealmModel = bgrealm.createObject(RealmModel.class);
//INSERTION
myrealmModel.setFirstName("aik aur stable");
myrealmModel.setLastName("aik aur kam stable");
myrealmModel.setMeraarray(meraarraykavalues);
}
}, new Realm.Transaction.OnSuccess() {
@OverRide
public void onSuccess() {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show();
}
}, new Realm.Transaction.OnError() {
@OverRide
public void onError(Throwable error) {
Toast.makeText(getApplicationContext(), "There was an error"+error.toString(), Toast.LENGTH_SHORT).show();
Log.d("kuchbhe", error.toString());
}
});

some other code...

Error:(12, 8) error: Field "meraarray" of type "java.lang.String[]" is not supported.Warning:Unclosed files for the types '[io.realm.RealmModelRealmProxy]'; these types will not undergo annotation processing

@bmunkholm
Copy link
Contributor

Did you see this: https://realm.io/docs/java/latest#lists-of-primitives?

Please list the SO questions. They are likely old and we should update the answers. Also let us know how we can make it more discoverable in the docs!

@bmunkholm
Copy link
Contributor

Perhaps we should have it as an example in the first model we show under "Models".

@FahdSaif
Copy link
Author

@Zhuinden
Copy link
Contributor

Use RealmList<String> instead of String[].

@bmunkholm
Copy link
Contributor

@FahdSaif Thanks for those links! I've now posted updates to all 3. Let me know if you can find more :-)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants