1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Android】Realmで 'Hoge' has a primary key... が出た時の対処法

Last updated at Posted at 2019-09-16

注 私はAndroid初学者です。誤情報などありましたらご指摘ください。

#概要
エラーメッセージ
 'Hoge' has a primary key, use 'createObject(class, Object)' instead

#原因
Realmのバージョンの違いによる文法の変化の影響のようです。

"Realm2.0.0からの変化でプライマリキーはオブジェクトを生成した後に変更できなくなった"(下記リンクより引用)

2.0.0以前

HogeActivity.java
Hoge hoge = createObject(Hoge.class);
hoge.setPrimaryKey(primaryKey);

2.0.0以降

HogeActivity.java
Hoge hoge = createObject(Hoge.class, primaryKey);

#解決方法
2.0.0以降の場合は上記の書き方に直せば解決します。

#参考文献
stack overflow - 'User' has a primary key, use 'createObject(Class, Object)' instead

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?