android でrealm使用するため使ったのですがうまくいかず止まっている状況でしてご教示いただければと思います。
手順書の通り
build.gradleに追記を2箇所してsync now、
デバック実行で初期化するところてこけてしまいます。
MainActivity.java
1package yobe.sandboxrealm2; 2 3import android.content.Context; 4import android.support.v7.app.AppCompatActivity; 5import android.os.Bundle; 6import android.widget.TextView; 7 8import io.realm.Realm; 9import io.realm.RealmResults; 10 11import yobe.sandboxrealm2.realm.UsersInfo; 12 13public class MainActivity extends AppCompatActivity { 14 15 private Realm realm; 16 private Context context; 17 // 18 19 @Override 20 protected void onCreate(Bundle savedInstanceState) { 21 super.onCreate(savedInstanceState); 22 setContentView(R.layout.activity_main); 23 24 25 Realm.init(context);←ここでこけます。 context null 26 27 realm = Realm.getDefaultInstance(); 28 realm.beginTransaction(); 29 30 RealmResults<UsersInfo> user = realm.where(UsersInfo.class).findAll(); 31 32 realm.close(); 33 34 35 TextView textView1 = (TextView)findViewById(R.id.user_name); 36 TextView textView2 = (TextView)findViewById(R.id.user_age); 37 TextView textView3 = (TextView)findViewById(R.id.user_detail); 38 39 textView1.setText(user.get(0).getName()); 40 textView2.setText(user.get(0).getAge()); 41 textView3.setText(user.get(0).getDeteil()); 42 43 44 } 45 46} 47 48``````UsersInfo.java 49package yobe.sandboxrealm2.realm; 50 51import java.util.Date; 52 53import io.realm.RealmObject; 54import io.realm.annotations.PrimaryKey; 55 56/** 57 * Created by yobe on 2017/05/27. 58 */ 59 60public class UsersInfo extends RealmObject { 61 @PrimaryKey 62 private long id; 63 private Date dateline; 64 private String name; 65 private int age; 66 private String deteil; 67 68 public long getId() { 69 return id; 70 } 71 72 public void setId(long id) { 73 this.id = id; 74 } 75 76 public Date getDateline() { 77 return dateline; 78 } 79 80 public void setDateline(Date dateline) { 81 this.dateline = dateline; 82 } 83 84 public String getName() { 85 return name; 86 } 87 88 public void setName(String name) { 89 this.name = name; 90 } 91 92 public int getAge() { 93 return age; 94 } 95 96 public void setAge(int age) { 97 this.age = age; 98 } 99 100 public String getDeteil() { 101 return deteil; 102 } 103 104 public void setDeteil(String deteil) { 105 this.deteil = deteil; 106 } 107} 108
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/28 22:20