error java.lang.NoSuchMethodError in java-mongodb example
<p>I have been trying to execute my first mongodb example in java. Its showing me the error. I have installed everything properly. Any help would be appreciated.it is throwing an exception Exception in thread "main" </p>

<blockquote>
  <p>java.lang.NoSuchMethodError:
  com.mongodb.ReadPreference.primary()Lcom/mongodb/ReadPreference;  at
  com.mongodb.MongoClientOptions$Builder.(MongoClientOptions.java:731)
    at com.mongodb.MongoClient.(MongoClient.java:151)     at
  com.mongodb.MongoClient.(MongoClient.java:141)  at
  mongoDBExample.main(mongoDBExample.java:21)</p>
</blockquote>

<p>This is my program code.</p>

<pre><code>   public class mongoDBExample {
    public static void main(String[] args) throws UnknownHostException {

    try {

    /**** Connect to MongoDB ****/

    MongoClient mongo = new MongoClient("localhost", 27017);

    /**** Get database ****/
    // if database doesn't exists, MongoDB will create it for you
    DB db = mongo.getDB("testdb");

    /**** Get collection / table from 'testdb' ****/
    // if collection doesn't exists, MongoDB will create it for you
    DBCollection table = db.getCollection("user");

    /**** Insert ****/
    // create a document to store key and value


    BasicDBObject document = new BasicDBObject();
    document.put("name", "mkyong");
    document.put("age", "30");
    document.put("createdDate", new Date());
    table.insert(new DBObject[] {document});


    /**** Find and display ****/
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("name", "mkyong");

    DBCursor cursor = table.find(searchQuery);

    while (cursor.hasNext()) {
        System.out.println(cursor.next());
    }

    /**** Update ****/
    // search document where name="mkyong" and update it with new values
    BasicDBObject query = new BasicDBObject();
    query.put("name", "mkyong");

    BasicDBObject newDocument = new BasicDBObject();
    newDocument.put("name", "mkyong-updated");

    BasicDBObject updateObj = new BasicDBObject();
    updateObj.put("$set", newDocument);

    table.update(query, updateObj);

    /**** Find and display ****/
    BasicDBObject searchQuery2
        = new BasicDBObject().append("name", "mkyong-updated");

    DBCursor cursor2 = table.find(searchQuery2);

    while (cursor2.hasNext()) {
        System.out.println(cursor2.next());
    }

    /**** Done ****/
    System.out.println("Done");

    } catch (MongoException e) {
    e.printStackTrace();
    }

  }
}
</code></pre>