title: copying database file from /assets to /data/data folder in file explorer - Android
body: <p>I have issues in copying database file from /assets to /data/data folder in file explorer. I have searched this website, found many answers, but could not find the appropriate answer that suits my context. I have created the database externally with SQLite Manager and imported it into assets folder. Now, when I run my application, I am getting NullPointerException in the emulator. I found that the package has not created in /data/data folder at all. But the application is launching in the emulator. The debugger also did not show any errors. </p>
  
  <p>I have tried the following solutions - </p>
  
  <p>Restarted eclipse and emulator, deleted and recreated existing emulator, finally restarted laptop</p>
  
  <p>None of the solutions solved my problem. Can any one please tell me, whats my mistake?</p>
  
  <p>Here is my MainActivity.java :-</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener
  {
  Dialog d;
  private photoDbAdapters mDbAdapter;
  public int currentimageindex=0;
   String[] sp;   
  
  int p=1;
  
   @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          images();
   }
   public void images()
   {
          try{
              String rt=mDbAdapter.fetchsingles(); //the application 
                                             is getting crashed in this part
  
          int id = getResources().getIdentifier(rt, null, null);
          ImageView iv = (ImageView) findViewById(R.id.ImageView3_Left);
          iv.setImageResource(id);
      }catch(NullPointerException er)
  {
          String ht=er.toString();
          Toast.makeText(getApplicationContext(), ht, Toast.LENGTH_LONG).show    ();
      }}
  
  
  @Override
  public void onClick(View v)
  {
      finish();
      android.os.Process.killProcess(android.os.Process.myPid());
      // TODO Auto-generated method stub
  }
  </code></pre>
  
  <p>fetchsingles method :- (this method will retreive image file name from database)</p>
  
  <pre><code>public String fetchsingles()
  {
  
      try{
  
  img = mDbHelper.getData();
  
  
      }catch(Exception e)
      {
          String error= e.toString();
          Dialog d = new Dialog(null);
          d.setTitle("image cannot be fetched");
          int err=Integer.parseInt(error);
          d.setContentView(err);
          d.show();
      }
      return img;
  
  
  }
  </code></pre>
  
  <p>getdata method:-</p>
  
  <pre><code>public String getData() 
  {
      // TODO Auto-generated method stub
  
      String dry="SELECT "+COL_DATA+" FROM Photos WHERE "+COL_ID+"=2;";
  
          Cursor c = myDataBase.rawQuery(dry,null);
  
          String result = "";
          int img = c.getColumnIndex(COL_DATA);
  
  
              result = c.getString(img);
  
  
  
  
  
      return dry;
  </code></pre>
  
  <p>The code might look lengthy, don't mind anything and please help me in solving this problem. </p>
  
  <p>Thanks in advance. </p>