我正在尝试使用Realm Mobile Database,但我遇到了一些问题:
我安装了Realm对象服务器,并尝试使用活动创建一个用途。
这是我的RegisterActivity
public class RegisterActivity extends AppCompatActivity implements SyncUser.Callback {
private AutoCompleteTextView usernameView;
private EditText passwordView;
private EditText passwordConfirmationView;
private View progressView;
private View registerFormView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
usernameView = (AutoCompleteTextView) findViewById(R.id.username);
passwordView = (EditText) findViewById(R.id.password);
passwordConfirmationView = (EditText) findViewById(R.id.password_confirmation);
passwordConfirmationView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
if (id == R.id.register || id == EditorInfo.IME_NULL) {
attemptRegister();
return true;
}
return false;
}
});
final Button mailRegisterButton = (Button) findViewById(R.id.email_register_button);
mailRegisterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
attemptRegister();
}
});
registerFormView = findViewById(R.id.register_form);
progressView = findViewById(R.id.register_progress);
}
private void attemptRegister() {
usernameView.setError(null);
passwordView.setError(null);
passwordConfirmationView.setError(null);
final String username = usernameView.getText().toString();
final String password = passwordView.getText().toString();
final String passwordConfirmation = passwordConfirmationView.getText().toString();
boolean cancel = false;
View focusView = null;
if (isEmpty(username)) {
usernameView.setError(getString(R.string.error_field_required));
focusView = usernameView;
cancel = true;
}
if (isEmpty(password)) {
passwordView.setError(getString(R.string.error_field_required));
focusView = passwordView;
cancel = true;
}
if (isEmpty(passwordConfirmation)) {
passwordConfirmationView.setError(getString(R.string.error_field_required));
focusView = passwordConfirmationView;
cancel = true;
}
if (!password.equals(passwordConfirmation)) {
passwordConfirmationView.setError(getString(R.string.error_incorrect_password));
focusView = passwordConfirmationView;
cancel = true;
}
if (cancel) {
focusView.requestFocus();
} else {
showProgress(true);
SyncUser.loginAsync(SyncCredentials.usernamePassword(username, password, true), AUTH_URL, new SyncUser.Callback() {
@Override
public void onSuccess(SyncUser user) {
registrationComplete(user);
}
@Override
public void onError(ObjectServerError error) {
showProgress(false);
String errorMsg;
switch (error.getErrorCode()) {
case EXISTING_ACCOUNT:
errorMsg = "Account already exists";
break;
default:
errorMsg = error.toString();
}
RealmLog.info(errorMsg);
Toast.makeText(RegisterActivity.this, errorMsg, Toast.LENGTH_LONG).show();
}
});
}
}
private void registrationComplete(SyncUser user) {
UserManager.setActiveUser(user);
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
private void showProgress(final boolean show) {
final int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
registerFormView.setVisibility(show ? View.GONE : View.VISIBLE);
registerFormView.animate().setDuration(shortAnimTime).alpha(
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
registerFormView.setVisibility(show ? View.GONE : View.VISIBLE);
}
});
progressView.setVisibility(show ? View.VISIBLE : View.GONE);
progressView.animate().setDuration(shortAnimTime).alpha(
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
progressView.setVisibility(show ? View.VISIBLE : View.GONE);
}
});
}
@Override
public void onSuccess(SyncUser user) {
registrationComplete(user);
}
@Override
public void onError(ObjectServerError error) {
String errorMsg;
switch (error.getErrorCode()) {
case EXISTING_ACCOUNT:
errorMsg = "Account already exists";
break;
default:
errorMsg = error.toString();
}
RealmLog.info(errorMsg);
Toast.makeText(RegisterActivity.this, errorMsg, Toast.LENGTH_LONG).show();
}
}
但是当我点击验证或我的视图上的按钮时,它会崩溃堆栈
java.lang.UnsatisfiedLinkError: No implementation found for void io.realm.log.RealmLog.nativeLog(int, java.lang.String, java.lang.Throwable, java.lang.String) (tried Java_io_realm_log_RealmLog_nativeLog and Java_io_realm_log_RealmLog_nativeLog__ILjava_lang_String_2Ljava_lang_Throwable_2Ljava_lang_String_2)
at io.realm.log.RealmLog.nativeLog(Native Method)
at io.realm.log.RealmLog.log(RealmLog.java:371)
at io.realm.log.RealmLog.info(RealmLog.java:263)
at io.realm.log.RealmLog.info(RealmLog.java:252)
at com.activity.user.RegisterActivity$3.onError(RegisterActivity.java:126)
at io.realm.SyncUser$1$1.run(SyncUser.java:206)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
或者当我评论所有RealmLog行
时No implementation found for void io.realm.log.RealmLog.nativeLog(int, java.lang.String, java.lang.Throwable, java.lang.String) (tried Java_io_realm_log_RealmLog_nativeLog and Java_io_realm_log_RealmLog_nativeLog__ILjava_lang_String_2Ljava_lang_Throwable_2Ljava_lang_String_2
编辑: 这里是gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "********"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "0.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "OBJECT_SERVER_IP", "\"XXXX\""
}
debug {
// This will automatically detect the IP address of the machine building RealmTasks.
// It is assumed that this machine is also running the Object Server.
// If not, replace 'host' with the IP of the machine hosting the server.
buildConfigField "String", "OBJECT_SERVER_IP", "\"XXXX\""
}
}
dataBinding {
enabled = true;
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
realm {
syncEnabled = true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(path: ':androidhttprequestlibrairy')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'
compile 'com.github.amlcurran.showcaseview:library:5.0.0'
compile 'org.jsoup:jsoup:1.7.3'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'org.apache.commons:commons-collections4:4.1'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'io.realm:android-adapters:1.4.0'
testCompile 'junit:junit:4.12'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
}
答案 0 :(得分:6)
您需要先调用init
Realm.init()