简体   繁体   English

如何使用Android手机运行领域而不会崩溃?

[英]How to run realm with android phone without crashing?

  1. So I just started using realm 5.8 and I cannot run with a mobile device it just crashes the app without any errors shown? 所以我刚开始使用5.8领域,却无法在移动设备上运行,它只是崩溃了应用程序而没有显示任何错误? what should I do? 我该怎么办?

Calling init and DefaultConf 调用init和DefaultConf

 import android.app.Application;
 import io.realm.Realm;
 import io.realm.RealmConfiguration;

 public class RealmApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Realm.init(this);
        RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();
        Realm.setDefaultConfiguration(realmConfiguration);
    }
   }

And now the Activity file there we are trying to send input fields username and user_id to the database. 现在,我们尝试在其中的活动文件将输入字段username和user_id发送到数据库。 I have on destroy getdefaultInstance() but nothing seems to work it just crashes? 我有销毁getdefaultInstance(),但似乎没有任何作用,只是崩溃了? Do I need to somehow download the database to phone in order to make this work? 我是否需要以某种方式将数据库下载到电话上才能进行这项工作? Well, I have no idea more than I look less I think to understand. 好吧,我不知道多于看上去不怎么了解。

     Realm realm;
 @Override
      protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.friends);
 username = (EditText)findViewById(R.id.editText);
    user_id = (EditText)findViewById(R.id.editText);
    submit = (Button)findViewById(R.id.button2);
    submit.setOnClickListener(this);

    realm = Realm.getDefaultInstance();
    }

     public void onClick(View view) {
    writeToDB(username.getText().toString().trim(), Integer.parseInt(user_id.getText().toString().trim()));
  }

 public void writeToDB(String username, int user_id) {
realm.executeTransactionAsync(new Realm.Transaction() {
    @Override
    public void execute(Realm bgRealm) {
        Friend user = bgRealm.createObject(Friend.class);
        user.setUsername(username);
        user.setUser_id(user_id);
    }
}, new Realm.Transaction.OnSuccess() {
    @Override
    public void onSuccess() {
        // Transaction was a success.
        Log.v("Database","database success");
    }
}, new Realm.Transaction.OnError() {
    @Override
    public void onError(Throwable error) {
        // Transaction failed and was automatically canceled.
    }
});
}

   @Override
    protected void onDestroy() {
    super.onDestroy();
    realm.close();
    }

好吧,您不应该将自己的设置重置为xampp来使用xampp,现在我可以在同一项目中运行mysqli和realm了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM