Retreiving data from SQLite database in another Activity
<p>I have created 3 activities including DBAdapter for database.
One is for saving the data and another is for retreiving the data from the SQLitedatabase created in DBAdapter class.
The creation of database has completed successfully.</p>

<p>mainActivity code for saving:</p>

<pre><code>DBAdapter db=new DBAdapter(this); 
save=(Button)findViewById(R.id.save);
 save.setOnClickListener(new View.OnClickListener() 
        {

            public void onClick(View v) 
            {
                try 
                {
                    db.open();
                } 
                catch (SQLException e) 
                {
                    e.printStackTrace();
                }
                String s=nme.getText().toString();
                String em=email.getText().toString();

                long id=db.insertContact(s,em);
                Toast.makeText(DataActivity.this, "Saved", 20).show();
                db.close();
            }
    });
</code></pre>

<p>For retreiving the data I created the object in another Activity called RetrieveActivity </p>

<p>RetreiveActivity code for retreiving:</p>

<pre><code>DBAdapter db=new DBAdapter(this);
        try {
            db.open();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        srch.setOnClickListener(new View.OnClickListener() 
        {   
            public void onClick(View v) 
            {
                Cursor c=db.getAllContacts();
                no1.setText(c.getString(0));
                nm1.setText(c.getString(1));
                em1.setText(c.getString(2));

            }
        });

    db.close(); 
</code></pre>

<p>But while clicking the button for retreiving "Force to close command" occured.
My doubt is with creating the object for DBAdapter.Can I access the Created database with an object from other Activity..?
Thanks in advance....</p>
