Realm NoClassDefFoundError: rx.Observable

非 Y 不嫁゛ 提交于 2020-01-14 14:47:10

问题


I am experiencing an issue that is pointed out in Realm's documentation:

Jackson Databind

Jackson Databind is a library for binding JSON data to Java classes.

Jackson uses reflection to perform the data binding. This conflicts with Realm’s support for RxJava, as RxJava might not be available to the class loader. This can result in an exception that looks like this:

Copy to clipboardjava.lang.NoClassDefFoundError: rx.Observable
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
...

Here is the proposed fix:

This can be fixed by either adding RxJava to your project or create two empty dummy files that looks like the following.

Copy to clipboard// File 1
package io.reactivex;

public class Flowable {
}


// File 2
package io.reactivex;

public class Observable {
}

This issue has also been reported to the Jackson project here.

Question: Where do I create the files so they don't have my app's package name? (ex: com.myApp.myPackage)

Side note: I'm experiencing this from SimpleXml, not Jackson (maybe simplexml uses jackson?). I've seen 2 errors:

  1. Realm NoClassDefFoundError: rx.Observable Realm
  2. NoClassDefFoundError: io.reactivex.Observable

回答1:


You are using Realm older than v4.0.0, so you need to create package rx, and the dummy class called Observable. But you just need to create it in src/main/java/rx.

package rx;

public class Observable {
}

For Realm 4.0.0+, you need in src/main/java/io/reactivex.

package io.reactivex;

public class Observable {
}

and

package io.reactivex;

public class Flowable {
}

and

package io.reactivex;

public enum BackpressureStrategy {
  MISSING,
  ERROR,
  BUFFER,
  DROP,
  LATEST
}


来源:https://stackoverflow.com/questions/47061821/realm-noclassdeffounderror-rx-observable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!