title: code to connect to mongoDB error, imported jar not recognized
body: <p>i am trying to connect to mogoDB database, i installed mongoDB as explained in </p>
  
  <p><a href="http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/" rel="nofollow">http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/</a></p>
  
  <p>and played with mongo via mongoshell in ubuntu terminal, everything is savvy, then i tried to implement it in an android application. i referred to this tutorial</p>
  
  <p><a href="http://www.mkyong.com/mongodb/java-mongodb-insert-a-document/" rel="nofollow">http://www.mkyong.com/mongodb/java-mongodb-insert-a-document/</a></p>
  
  <p>and edited it to create my code listed below</p>
  
  <p>package com.example.test1;</p>
  
  <pre><code>import java.net.UnknownHostException;
  import java.text.MessageFormat;
  import java.util.Set;
  
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ProgressBar;
  import android.widget.TextView;
  
  import com.mongodb.DB;
  import com.mongodb.MongoClient;
  
  public class InsertDocumentApp extends ActionBarActivity {
  private Button btnRestart;
  private Button btnCancel = null;
  private TextView txtMessage =  null;
  private TextView txt=null;
  private ProgressBar mProgressBar =  null;
  private HugeWork task = null;
  private static final int MAX_PROGRESS = 10;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.showdata);
  
      btnRestart = (Button) findViewById(R.id.btnRestart);
      btnCancel = (Button) findViewById(R.id.btnCancel);
      txtMessage = (TextView) findViewById(R.id.txtMessage);
      mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
      txt =  (TextView) findViewById(R.id.textViewname);
      // set an arbitrary max value for the progress bar
      mProgressBar.setMax(MAX_PROGRESS);
      // start the async task
      start();
  }
  
  
  public void cancelOnclick(View v) {
      task.cancel(true);
      btnCancel.setEnabled(false);
      btnRestart.setEnabled(true);
  }
  
  // Restart the process execution. This is the listener to the Restart button.
  public void restartOnclick(View v) {
      start();
  }
  
  
  private void start() {
  
      task = new HugeWork();
  
      task.execute(0);
  
      mProgressBar.setProgress(0);
  
      btnCancel.setEnabled(true);
      btnRestart.setEnabled(false);
  }
  
  
  private void executeHardWork() 
  {
      MongoClient mongoClient;
      DB db;
      try {
          try
          { 
          mongoClient = new MongoClient(); //connects to mongo server locally (seems to work)
          // mongoClient = new MongoClient("localhost",27017); //connects to mongo server locally (seems to work)
          mongoClient = new MongoClient("localhost",27017); // connects to mongo server locally
          db = mongoClient.getDB("mydb"); // connect to a database --implicitly creates database if none exists
          Set&lt;String&gt; colls = db.getCollectionNames();
          for (String s : colls)
              System.out.println(s);
  
          mongoClient.close();
  
          } catch (UnknownHostException ex) {
          ex.printStackTrace();
          }
      }
      catch(Exception e)
      {
          System.out.println(e);
      }
  } 
  
          @Override
      protected void onPreExecute() {
          txtMessage.setText("Executing async task...");
          super.onPreExecute();
      }
  
  
      @Override
      protected Integer doInBackground(Integer... params) {
  
  
          int progress = ((Integer[])params)[0];
  
          do {
  
                              if (!this.isCancelled()) {
                  // execute hard work - sleep
                  executeHardWork();
              }
              else {
                                      break;
              }
  
  
              progress++;
              publishProgress(progress);
          } while (progress &lt;= MAX_PROGRESS);
  
          return progress;
      }
  
  
      @Override
      protected void onProgressUpdate(Integer... values) {
          int progress = ((Integer[])values)[0];
          mProgressBar.setProgress(progress);
          super.onProgressUpdate(values);
      }
  
  
      @Override
      protected void onCancelled(Integer result) {
          txtMessage.setText(MessageFormat.format
          ("Async task has been cancelled at {0} seconds.", result - 1));
          super.onCancelled(result);
      }
  
  
      @Override
      protected void onPostExecute(Integer result) {
          txtMessage.setText(MessageFormat.format
          ("Async task execution finished in {0} seconds.", result - 1));
          btnCancel.setEnabled(false);
          btnRestart.setEnabled(true);
          super.onPostExecute(result);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>i noticed that some imports in the tutorial are not coming in ADT even after i imported jar file which i got from this link</p>
  
  <p><a href="http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.11.3/" rel="nofollow">http://central.maven.org/maven2/org/mongodb/mongo-java-driver/2.11.3/</a></p>
  
  <p>this is the jar file i downloaded <code>mongo-java-driver-2.11.3.jar</code>
  i imported it by, project/buildpath/add external jar
  errors are showing everywhere with 'mongo items' are there.
  is it because eclipse is not recognizing jar file i added to build path?
  is this the correct jar file? do i need to do anything more to get my app running?  </p>
  
  <p>this is the terminal prompt which occurs as i type mongo in terminal</p>
  
  <pre><code>mukund@mukund-ThinkPad-Edge-E431:~$ mongo
  MongoDB shell version: 2.4.10
  connecting to: test
  Server has startup warnings: 
  Wed Apr  9 10:03:04.513 [initandlisten] 
  Wed Apr  9 10:03:04.513 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
  Wed Apr  9 10:03:04.513 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal). 
  Wed Apr  9 10:03:04.513 [initandlisten] **       Note that journaling defaults to off for 32 bit and is currently off.
  Wed Apr  9 10:03:04.513 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
  Wed Apr  9 10:03:04.513 [initandlisten] 
  &gt; 
  </code></pre>
  
  <p>i can get into database via terminal, but in ADT now the following errors are shown.</p>
  
  <p>is der any problem in using 32bit ubuntu?</p>
  
  <p>and the logcat is</p>
  
  <pre><code>04-09 10:03:47.175: W/com.mongodb.tcp(2682): Exception executing isMaster command on localhost/127.0.0.1:27017
  04-09 10:03:47.175: W/com.mongodb.tcp(2682): java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 2 7017) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at libcore.io.IoBridge.isConnected(IoBridge.java:223)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at libcore.io.IoBridge.connect(IoBridge.java:112)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at java.net.Socket.connect(Socket.java:843)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBPort._open(DBPort.java:223)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBPort.go(DBPort.java:125)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBPort.go(DBPort.java:106)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBPort.findOne(DBPort.java:162)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBPort.runCommand(DBPort.java:170)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at   co m.mongodb.DBTCPConnector.initDirectConnection(DBTCPConnector.java:547)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:526)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:236)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.mongodb.DB.getCollectionNames(DB.java:400)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.example.test1.InsertDocumentApp.executeHardWork(InsertDocumentApp.java:87)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.example.test1.InsertDocumentApp.access$1(InsertDocumentApp.java:76)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.example.test1.InsertDocumentApp$HugeWork.doInBackground(InsertDocumentApp.java:151)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at com.example.test1.InsertDocumentApp$HugeWork.doInBackground(InsertDocumentApp.java:1)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at java.lang.Thread.run(Thread.java:841)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682): Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    at libcore.io.IoBridge.isConnected(IoBridge.java:208)
  04-09 10:03:47.175: W/com.mongodb.tcp(2682):    ... 27 more
  04-09 10:03:47.175: W/com.mongodb(2682): emptying DBPortPool to localhost/127.0.0.1:27017 b/c of error
  04-09 10:03:47.175: W/com.mongodb(2682): java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 27017) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
  04-09 10:03:47.175: W/com.mongodb(2682):    at libcore.io.IoBridge.isConnected(IoBridge.java:223)
  04-09 10:03:47.175: W/com.mongodb(2682):    at libcore.io.IoBridge.connectErrno(IoBridge.java:161)
  04-09 10:03:47.175: W/com.mongodb(2682):    at libcore.io.IoBridge.connect(IoBridge.java:112)
  04-09 10:03:47.175: W/com.mongodb(2682):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
  04-09 10:03:47.175: W/com.mongodb(2682):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
  04-09 10:03:47.175: W/com.mongodb(2682):    at java.net.Socket.connect(Socket.java:843)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DBPort._open(DBPort.java:223)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DBPort.go(DBPort.java:125)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DBPort.call(DBPort.java:92)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:244)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.mongodb.DB.getCollectionNames(DB.java:400)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.example.test1.InsertDocumentApp.executeHardWork(InsertDocumentApp.java:87)
   04-09 10:03:47.175: W/com.mongodb(2682):   at com.example.test1.InsertDocumentApp.access$1(InsertDocumentApp.java:76)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.example.test1.InsertDocumentApp$HugeWork.doInBackground(InsertDocumentApp.java:151)
  04-09 10:03:47.175: W/com.mongodb(2682):    at com.example.test1.InsertDocumentApp$HugeWork.doInBackground(InsertDocumentApp.java:1)
  04-09 10:03:47.175: W/com.mongodb(2682):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
  04-09 10:03:47.175: W/com.mongodb(2682):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
  04-09 10:03:47.175: W/com.mongodb(2682):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
  04-09 10:03:47.175: W/com.mongodb(2682):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  04-09 10:03:47.175: W/com.mongodb(2682):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  04-09 10:03:47.175: W/com.mongodb(2682):    at java.lang.Thread.run(Thread.java:841)
  04-09 10:03:47.175: W/com.mongodb(2682): Caused by: libcore.io.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
  04-09 10:03:47.175: W/com.mongodb(2682):    at libcore.io.IoBridge.isConnected(IoBridge.java:208)
  04-09 10:03:47.175: W/com.mongodb(2682):    ... 23 more
  04-09 10:03:47.255: D/dalvikvm(2682): GC_FOR_ALLOC freed 215K, 1% free 117331K/117612K, paused 36ms, total 36ms
  04-09 10:03:47.315: D/dalvikvm(2682): GC_FOR_ALLOC freed 27K, 1% free 119327K/119424K, paused 32ms, total 32ms
   04-09 10:03:47.375: D/dalvikvm(2682): GC_FOR_ALLOC freed 27K, 1% free 121338K/121432K, paused 34ms, total 34ms
  04-09 10:03:47.375: I/System.out(2682): com.mongodb.MongoException$Network: Read operation to server localhost/127.0.0.1:27017 failed on database mydb
  </code></pre>