0

I am trying to write a little test-programm with different Databases. MongoDB is one of them and it worked perfectly fine until last Friday, even though I didn't change anything in the java code of my MongoDB class.

System: I use an ubuntu 14.04 VM with the package mongo-org. The version of mongo is 3.0.5.

I also run MariaDB, PostgreSQL and Cassandra on the VM. As a Client, I have windows 7 and Eclipse.

The connection and the test work perfectly fine with the other 3 databases.

And I can run the "mongo" client on ubuntu as well.

But when I try out the Java Test of MongoDB, I keep getting this error:

Exception in thread "main" java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.mongodb.MongoClientOptions$Builder.<init>(MongoClientOptions.java:52)
    at com.mongodb.MongoClient.<init>(MongoClient.java:126)
    at com.mongodb.MongoClient.<init>(MongoClient.java:115)
    at de.motza.database.impl.DatabaseImplMongoDB.connect(DatabaseImplMongoDB.java:197)
    at de.motza.database.impl.DatabaseImplMongoDB.instantiate(DatabaseImplMongoDB.java:207)
    at de.motza.test.History_Log.testNewDatabase(History_Log.java:86)
    at de.motza.test.History_Log.main(History_Log.java:66) 

The part of the java Class, where the Exception occurs:

private static String dbHost = "10.158.251.251";
private static int dbPort = 27017;
private static String dbName = "history_log";
private static MongoClient mongoClient = null;
[...]
@Override
    public void connect() {
        try {
            mongoClient = new MongoClient(dbHost, dbPort);
            db = mongoClient.getDB(dbName);
        } catch (Exception e) {
            log.error(e);
        }

    }

I read about the disk-space, but I habe 12 GB free in my VM, so I do not think that this is the problem. I ran apt-get upgrade, but it didn't change anything either. I also reinstalled mongoDb, but nothing changed. I also tried to recompile, but nothing changed there either.

Does anybody have any advice?

ADDITION:

Here you find the library tab of my project. I use multiple databases, so I marked the ones important for MongoDB the library tab of my project

1 Answer 1

1

One possible reason for a IncompatibleClassChangeError you get is that a Mongo library binary has changed (for whatever reason) and now your earlier compiled test code isn't any more compatible with the library. I would suggest to recompile your test code and try again.

Sign up to request clarification or add additional context in comments.

6 Comments

I tried to clean up the project to do that @Sergey Pauk , but it didn't help. is there another way to force eclipse to recompile everything?
considering eclipse: is it a maven-based (or some other dependency framework) project or do you import all the libraries manually?
Could you make a screenshot of your project's JavaBuildPath/Libraries tab?
I added the screenshot and marked the packages important for MongoDB
Try to remove bson-2.3.jar for a while and see if the code works. mongo-java-driver comes with it's own built-in version of bson. UPDATE: i've just checked with maven build that mongo-java-driver doesn't have a transient dependency on bson meaning that it has all it needs already built-in.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.