3

I have a pre-initialized .realm file that I'm trying to access in Android Studio. I have used Realm browser to figure out the exact schema to model my classes after (i.e. field names and types), but I can't figure out what the Any type of the comments field (see screenshot below) should be in my code.

Realm Browser

According to this, the field can only be a boolean, short, ìnt, long, float, double, String, Date, byte[], subclasses of RealmObject, or RealmList<? extends RealmObject>. I've tried a bunch of different types for the comments field, but I continue to get errors similar to the following:

io.realm.exceptions.RealmMigrationNeededException: Invalid type 'String' for field 'comments'

When I try to allow comments to be as generic as possible by making its type RealmObject, my code fails to even compile successfully:

/Users/name/AndroidStudioProjects/Project/app/build/intermediates/classes/debug/io/realm/ReportRealmProxy.java
Error:(147, 17) error: cannot find symbol variable RealmObjectRealmProxy
Error:(285, 48) error: cannot find symbol variable RealmObjectRealmProxy
Error:(330, 52) error: cannot find symbol variable RealmObjectRealmProxy
Error:(374, 41) error: cannot find symbol variable RealmObjectRealmProxy
Error:(420, 41) error: cannot find symbol variable RealmObjectRealmProxy

Finally, when I tried to use Realm Browser's automatic model code generation (File -> Save Model Definitions -> Save Java definitions...), the following code is produced:

import io.realm.RealmObject

public class Report extends RealmObject {
    private String term;
    private String year;
    private int enrollment;
    private Any comments;
    private RealmList<Response> responses;
    private RealmList<FacultyReport> facultyReports;
}

Unfortunately, neither Android Studio nor I understand what the Any class is - I can't find any mention of it online.

Any help would be much appreciated, as I am unable to load the data without exactly matching the model definitions used to create it. If there were a way to load all the data except the Report class/table, that would work too, because it is currently empty (as the screenshot shows). But, currently, even though it is empty, my inability to model it is preventing me from loading any objects at all!

Edit: Here is my Report.java class code:

import io.realm.RealmList;
import io.realm.RealmObject;

public class Report extends RealmObject {
    private String term;
    private String year;
    private int enrollment;
    private ???? comments;
    private RealmList<Response> responses;
    private RealmList<FacultyReport> facultyReports;

    public ???? getComments() {
        return comments;
    }

    public void setComments(???? comments) {
        this.comments = comments;
    }

    // other getters and setters removed
}
vvvvv
  • 25,404
  • 19
  • 49
  • 81
asaini007
  • 858
  • 5
  • 19

2 Answers2

0

It seems like Realm Swift was missing a few cases where it wouldn't catch unsupported property types in models in some cases, therefore treating it as an 'Any' type (a.k.a. 'mixed').

I have a PR fixing the issue which is now pending review: https://github.com/realm/realm-cocoa/pull/2496

Although we may change the approach we're taking.

jpsim
  • 14,329
  • 6
  • 51
  • 68
-2

Have you noticed that you can make the Browser create Java code for the Class Definitions (look in the File menu)?

ast
  • 528
  • 2
  • 6
  • this is more suitable as a comment – EpicPandaForce Sep 04 '15 at 22:15
  • Thanks for the response. As I mentioned in my question, when I use this option, Realm Browser spits out code with `comment`'s type being `Any`, which is not a real class as far as I'm aware – asaini007 Sep 05 '15 at 14:36
  • 1
    Just to clarify: I work for Realm :-) The `Any` type is an unused type in Realm. I really don't understand how a `String` field can be interpreted as `Any` by the browser. Is it possible for you to share the Realm file so we can take a closer look? – geisshirt Sep 07 '15 at 06:24
  • @geisshirt I emailed it. To clarify, the type of `comments` shouldn't be `String`, but I'm not sure what it should be. Thanks for the help. – asaini007 Sep 08 '15 at 01:10