Solution 1 :
Try this:
- Change somehow the name
private
of your field. It’s a keyword in Java, so there could be problems.
.........................
var `private`: Boolean, <------ that's not good idea
.........................
- Move your fields annotated with
@Ignore
to the body of class.
...........................
): Parcelable {
@IgnoredOnParcel
@PrimaryKey(autoGenerate = true)
var repoId: Long = 0
@Ignore var owner: Owner <---------- move all your @Ignore fields here
...........................
}
Solution 2 :
This worked for me:
@Entity(tableName = "student")
data class Student @JvmOverloads constructor( //key point
var name: String,
var age: Int,
var gpa: Double,
var isSingle: Boolean,
@Ignore
var isSelected: Boolean = false,
@PrimaryKey(autoGenerate = true) //primary key field must be placed at the end
var id: Long = 0
)
Problem :
I ask you for help. I’ve already spent a lot of time solving the problem, but haven’t solved it yet.
I would like to place this model in the Room.
But I get problems all the time.
I’ve tried removing annotation
@Parcelize
But the result hasn’t changed.
@Entity
@Parcelize
data class UserRepositoryItem (
var archive_url: String,
var archived: Boolean,
var assignees_url: String,
var blobs_url: String,
var branches_url: String,
var clone_url: String,
var collaborators_url: String,
var comments_url: String,
var commits_url: String,
var compare_url: String,
var contents_url: String,
var contributors_url: String,
var created_at: String,
var default_branch: String,
var deployments_url: String,
var description: String,
var disabled: Boolean,
var downloads_url: String,
var events_url: String,
var fork: Boolean,
var forks: Int,
var forks_count: Int,
var forks_url: String,
var full_name: String,
var git_commits_url: String,
var git_refs_url: String,
var git_tags_url: String,
var git_url: String,
var has_downloads: Boolean,
var has_issues: Boolean,
var has_pages: Boolean,
var has_projects: Boolean,
var has_wiki: Boolean,
var homepage: String,
var hooks_url: String,
var html_url: String,
var id: Int,
var issue_comment_url: String,
var issue_events_url: String,
var issues_url: String,
var keys_url: String,
var labels_url: String,
var language: String?,
var languages_url: String,
@Ignore var license: License,
var merges_url: String,
var milestones_url: String,
var mirror_url: String?,
var name: String,
var node_id: String,
var notifications_url: String,
var open_issues: Int,
var open_issues_count: Int,
@Ignore var owner: Owner,
var `private`: Boolean,
var pulls_url: String,
var pushed_at: String,
var releases_url: String,
var size: Int,
var ssh_url: String,
var stargazers_count: Int,
var stargazers_url: String,
var statuses_url: String,
var subscribers_url: String,
var subscription_url: String,
var svn_url: String,
var tags_url: String,
var teams_url: String,
var trees_url: String,
var updated_at: String,
var url: String,
var watchers: Int,
var watchers_count: Int
): Parcelable {
@IgnoredOnParcel
@PrimaryKey(autoGenerate = true)
var repoId: Long = 0
}
I get an error every time.
error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
public final class UserRepositoryItem implements android.os.Parcelable {
^
Tried the following constructors but they failed to match:
I will greatly appreciate any answer, thanks!