title: Android Eclipse: database doesn't seem to work when APK is installed to an external device
body: <p>I am a beginner mobile developer and I am developing a directory app using eclipse for android. I am not really good in coding and programming so I really need help. </p>
  
  <p>My app works good in my laptop, in eclipse emulator but when I run it in my phone, or manually copy the apk and install it in my phone, the app works from the login activity, but when I start searching in the main activity, nothing happens, <strong>no error warning</strong>, <strong>no logcat error</strong> or anything else.</p>
  
  <p>I'm suspecting that the database isn't installed together with the apk, I have no idea what's happening and what to do, please help. Thanks in advance.</p>
  
  <pre><code>package samples.planholderdirectory;
  
  import android.content.Context;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  public class DatabaseHelper extends SQLiteOpenHelper {
  
      public static final String DATABASE_NAME = "planholder";
  
      public DatabaseHelper(Context context) {
          super(context, DATABASE_NAME, null, 1);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          /*
           * Create the planholder table and populate it with sample data.
           */
          String sql = "CREATE TABLE IF NOT EXISTS planholder (" +
                          "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                          "firstName TEXT, " +
                          "lastName TEXT, " +
                          "contractNo TEXT, " +
                          "plan TEXT, " +
                          "description TEXT, " +
                          "effectivity TEXT, " +
                          "dueDate TEXT, " +
                          "quotaComm TEXT, " +
                          "quotaNComm TEXT, " +
                          "CBI TEXT, " +
                          "instNo TEXT, " +
                          "aging TEXT, " +
                          "balance TEXT, " +
                          "taxable TEXT, " +
                          "insured TEXT, " +
                          "orNo TEXT, " +
                          "orDate TEXT, " +
                          "collDue TEXT, " +
                          "collAdvance TEXT, " +
                          "managerId INTEGER)";
  db.execSQL(sql);
  
  
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL("DROP TABLE IF EXISTS employees");
          onCreate(db);
      }
  
  }
  </code></pre>
  
  <p>This is my DatabaseHelper</p>
  
  <pre><code>package samples.planholderdirectory;
  
  import android.app.ListActivity;
  import android.content.Intent;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.EditText;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.SimpleCursorAdapter;
  
  public class PlanholderList extends ListActivity {
  
      protected EditText searchText;
      protected SQLiteDatabase db;
      protected Cursor cursor;
      protected ListAdapter adapter;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          db = (new DatabaseHelper(this)).getWritableDatabase();
          searchText = (EditText) findViewById (R.id.searchText);    
      }
  
      public void search(View view) {
          // || is the concatenation operation in SQLite and for lpa number
          cursor = db.rawQuery("SELECT _id, firstName, lastName, contractNo FROM planholder WHERE contractNo || ' ' || firstName || ' ' || lastName LIKE ?", 
                          new String[]{"%" + searchText.getText().toString() + "%"});
          adapter = new SimpleCursorAdapter(
                  this, 
                  R.layout.planholder_list_item, 
                  cursor, 
                  new String[] {"contractNo", "firstName", "lastName"}, 
                  new int[] {R.id.contractNo, R.id.firstName, R.id.lastName});
          setListAdapter(adapter);
      }
  
      public void onListItemClick(ListView parent, View view, int position, long id) {
          Intent intent = new Intent(this, PlanholderDetails.class);
          Cursor cursor = (Cursor) adapter.getItem(position);
          intent.putExtra("PLANHOLDER_ID", cursor.getInt(cursor.getColumnIndex("_id")));
          startActivity(intent);
      }
  
  }
  </code></pre>
  
  <p>this is my PlanholderList</p>
  
  <pre><code>package samples.planholderdirectory;
  
  import android.app.Activity;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class PlanholderDetails extends Activity {
  
      protected TextView planholderName;
      protected TextView contractNo;
      protected TextView plan;
      protected TextView description;
      protected TextView effectivity;
      protected TextView dueDate;
      protected TextView quotaComm;
      protected TextView quotaNComm;
      protected TextView CBI;
      protected TextView instNo;
      protected TextView aging;
      protected TextView balance;
      protected TextView taxable;
      protected TextView insured;
      protected TextView orNo;
      protected TextView orDate;
      protected TextView collDue;
      protected TextView collAdvance;
      protected int planholderId;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.planholder_details);
  
          planholderId = getIntent().getIntExtra("PLANHOLDER_ID", 0);
          SQLiteDatabase db = (new DatabaseHelper(this)).getWritableDatabase();
          Cursor cursor = db.rawQuery("SELECT emp._id, emp.firstName, emp.lastName, emp.contractNo, emp.plan, emp.description, emp.effectivity, emp.dueDate, emp.quotaComm, emp.quotaNComm, emp.CBI, emp.instNo, emp.aging, emp.balance, emp.taxable, emp.insured, emp.orNo, emp.orDate, emp.collDue, emp.collAdvance, emp.managerId, mgr.firstName managerFirstName, mgr.lastName managerLastName FROM planholder emp LEFT OUTER JOIN planholder mgr ON emp.managerId = mgr._id WHERE emp._id = ?", 
                  new String[]{""+planholderId});
          if (cursor.getCount() == 1)
          {
              cursor.moveToFirst();
  
              planholderName = (TextView) findViewById(R.id.planholderName);
              planholderName.setText(("Planholder: ")+ cursor.getString(cursor.getColumnIndex("firstName")) + " " + cursor.getString(cursor.getColumnIndex("lastName")));
  
              contractNo = (TextView) findViewById(R.id.contractNo);
              contractNo.setText(("LPA No.: ")+ cursor.getString(cursor.getColumnIndex("contractNo")));
  
              plan = (TextView) findViewById(R.id.plan);
              plan.setText(("Plan: ")+ cursor.getString(cursor.getColumnIndex("plan")));
  
              description = (TextView) findViewById(R.id.description);
              description.setText(("Description: ")+ cursor.getString(cursor.getColumnIndex("description")));
  
              effectivity = (TextView) findViewById(R.id.effectivity);
              effectivity.setText(("Effectivity Date: ")+ cursor.getString(cursor.getColumnIndex("effectivity")));
  
              dueDate = (TextView) findViewById(R.id.dueDate);
              dueDate.setText(("Due Date: ")+ cursor.getString(cursor.getColumnIndex("dueDate")));
  
              quotaComm = (TextView) findViewById(R.id.quotaComm);
              quotaComm.setText(("Quota Comm: ")+ cursor.getString(cursor.getColumnIndex("quotaComm")));
  
              quotaNComm = (TextView) findViewById(R.id.quotaNComm);
              quotaNComm.setText(("Quota NComm: ")+ cursor.getString(cursor.getColumnIndex("quotaNComm")));
  
              CBI = (TextView) findViewById(R.id.CBI);
              CBI.setText(("CBI: ")+ cursor.getString(cursor.getColumnIndex("CBI")));
  
              instNo = (TextView) findViewById(R.id.instNo);
              instNo.setText(("Inst No.: ")+ cursor.getString(cursor.getColumnIndex("instNo")));
  
              aging = (TextView) findViewById(R.id.aging);
              aging.setText(("Aging: ")+ cursor.getString(cursor.getColumnIndex("aging")));
  
              balance = (TextView) findViewById(R.id.balance);
              balance.setText(("Balance: ")+ cursor.getString(cursor.getColumnIndex("balance")));
  
              taxable = (TextView) findViewById(R.id.taxable);
              taxable.setText(("Taxable: ")+ cursor.getString(cursor.getColumnIndex("taxable")));
  
              insured = (TextView) findViewById(R.id.insured);
              insured.setText(("Insured: ")+ cursor.getString(cursor.getColumnIndex("insured")));
  
              orNo = (TextView) findViewById(R.id.orNo);
              orNo.setText(("OR Number: ")+ cursor.getString(cursor.getColumnIndex("orNo")));
  
              orDate = (TextView) findViewById(R.id.orDate);
              orDate.setText(("OR Date: ")+ cursor.getString(cursor.getColumnIndex("orDate")));
  
              collDue = (TextView) findViewById(R.id.collDue);
              collDue.setText(("Coll Due: ")+ cursor.getString(cursor.getColumnIndex("collDue")));
  
              collAdvance = (TextView) findViewById(R.id.collAdvance);
              collAdvance.setText(("Coll Advance: ")+ cursor.getString(cursor.getColumnIndex("collAdvance")));
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>this is my PlanholderDetails</p>
  
  <pre><code>package samples.planholderdirectory;
  
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  
  public class SampleLogin extends Activity {
  
   EditText txtUserName;
   EditText txtPassword;
   Button btnLogin;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.samplelogin);
  
          txtUserName=(EditText)this.findViewById(R.id.txtUname);
          txtPassword=(EditText)this.findViewById(R.id.txtPwd);
          btnLogin=(Button)this.findViewById(R.id.btnLogin);
          btnLogin=(Button)this.findViewById(R.id.btnLogin);
          btnLogin.setOnClickListener(new OnClickListener() {
  
     @Override
     public void onClick(View v) {
      // TODO Auto-generated method stub
  
      if((txtUserName.getText().toString()).equals("user") &amp;&amp; (txtPassword.getText().toString().equals("pass"))){
             Toast.makeText(SampleLogin.this, "Login Successful",Toast.LENGTH_LONG).show();
  
           /// Create Intent for SignUpActivity  and Start The Activity
              Intent intentSignUP=new Intent(getApplicationContext(), PlanholderList.class);
              startActivity(intentSignUP);
            } else{
             Toast.makeText(SampleLogin.this, "Invalid Login",Toast.LENGTH_LONG).show();
            }
  
     }
    });       
      }
      @Override
      public void onResume(){
          super.onResume();
  
          EditText username = (EditText) findViewById(R.id.txtUname);
          username.setText("");
          EditText password = (EditText) findViewById(R.id.txtPwd);
          password.setText("");
  
      }
  } 
  </code></pre>
  
  <p>this is my login activity</p>