I want to create Android application that can run while online and offline. It's possible to combine Realm.io for offline database and Firebase as Online service.
I'm trying to make simple application that directly add realm object to firebase, but i get error exception like this :
java.lang.NoClassDefFoundError: rx.Observable
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:476)
at java.lang.reflect.Method.getReturnType(Method.java:183)
at java.lang.Class.getDeclaredMethods(Class.java:672)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass._addMemberMethods(AnnotatedClass.java:593)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass.resolveMemberMethods(AnnotatedClass.java:421)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:243)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:457)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collect(POJOPropertiesCollector.java:233)
at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector.collectProperties(BasicClassIntrospector.java:142)
at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector.forSerialization(BasicClassIntrospector.java:68)
at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector.forSerialization(BasicClassIntrospector.java:11)
at com.fasterxml.jackson.databind.SerializationConfig.introspect(SerializationConfig.java:490)
at com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:133)
at com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:873)
at com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:833)
at com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:387)
at com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:478)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:97)
at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:2593)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:2542)
at com.firebase.client.Firebase.setValueInternal(Firebase.java:336)
at com.firebase.client.Firebase.setValue(Firebase.java:298)
at com.pringstudio.firebaserealm.MainActivity$1.onClick(MainActivity.java:56)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "rx.Observable" on path: DexPathList[[dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-tubesock-0.0.12_19946b0113470caa2e5e499f498247824b9e76d9-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-support-annotations-23.3.0_ce4b168a6a58bc3fcd41c2a9e083ac97b17599a0-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.pringstudio.firebaserealm/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.pringstudio.
Code
// Firebase Root
Firebase firebase = new Firebase("firebae_url");
Siswa siswa = new Siswa(
Integer.valueOf(editText.getText().toString()),
editTextNama.getText().toString()
);
Firebase refSiswa = firebase.child("siswa").child(String.valueOf(siswa.getId()));
refSiswa.setValue(siswa, new Firebase.CompletionListener() {
@Override
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
if (firebaseError != null) {
Log.e("Firebase Add", "Error: " + firebaseError.getMessage());
Toast.makeText(getApplicationContext(), "Gagal\n" + firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Data tersimpan", Toast.LENGTH_SHORT).show();
}
}
});
Object
package com.pringstudio.firebaserealm.model;
import io.realm.RealmObject;
/**
* Created by sucipto on 5/18/16.
*/
public class Siswa extends RealmObject{
private String nama;
private int id;
public Siswa(){};
public Siswa(int id, String nama){
this.id = id;
this.nama = nama;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNama() {
return nama;
}
public void setNama(String nama) {
this.nama = nama;
}
}
When i not extends RealmObject firebase can accept it, but when i convert Siswa Object to extends realm object, it's cause error.
I want my object compatible with firebase and realm, any sugestion? Thanks.
Realm offers offline first with a syncing component for online. Firebase is pretty much online only with a offline persistance for situations where the device temporarily looses connection.
The Realm database is an open-source, easy-to-use alternative to Core Data and SQLite. It's a non-relational, NoSQL database that allows you to set up relationships between different objects.
Realm is a mobile database that runs directly inside phones, tablets or wearables. This project hosts the JavaScript versions of Realm. Currently we support React Native (both iOS & Android), Node. js and Electron (on Windows, MacOS and Linux).
Firebase helps you develop high-quality apps, grow your user base, and earn more money. Each feature works independently, and they work even better together.
It looks like you are using Jackson Databind, and that is what is causing the problem. There is a description of the problem and a work-around here: https://realm.io/docs/java/latest/#jackson-databind
But to also have the answer here:
This can be fixed by either adding RxJava to your project or create an empty dummy file that looks like the following.
package rx;
public class Observable {
// Dummy class required for Jackson-Databind support if
// RxJava is not a project dependency.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With