title: How to insert and retrieve image from Sqlite database in Android Studio
body: <p>I'm attempting to take some data from a user including a picture taken by the camera and then insert that into the DB (thumbnail) and then retrieve it to be viewed later on.
  <a href="https://stackoverflow.com/questions/9357668/how-to-store-image-in-sqlite-database/9357943#9357943">1- I used this</a>
  <a href="https://stackoverflow.com/questions/9941637/android-how-to-save-camera-images-in-database-and-display-another-activity-in-li#">and this</a></p>
  
  <p>But i still get an error <a href="https://i.stack.imgur.com/VkYgl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VkYgl.png" alt="in this image"></a></p>
  
  <p>line 45 mentioned in this error is here:
  <a href="https://i.stack.imgur.com/no8pV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/no8pV.png" alt="This is the error"></a></p>
  
  <p>and this is the OnclickListener that responds to the user's input. </p>
  
  <pre><code>sginUpButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              String Fname = fn.getText().toString();
              String Lname = ln.getText().toString();
              String Email = em.getText().toString();
              String Pass = pass.getText().toString();
              String mobile = mob.getText().toString();
              if(fn.length()!=0 &amp;&amp; ln.length()!=0  &amp;&amp; em.length()!=0 &amp;&amp; pass.length()!=0&amp;&amp; mob.length()!=0)
              {
                  AddData(Fname,Lname,Email,Pass,mobile,byteArray);
                  fn.setText("");
                  ln.setText("");
                  em.setText("");
                  pass.setText("");
                  mob.setText("");
                  Intent fromLoginToSignup = new Intent(SignUpScreen.this, Profile.class);
                  notification();
              }
              else
              {
                  toastmessage("lazem temla kol al fara3'at");
              }
  
          }
      });
  </code></pre>
  
  <p>And finally, this is the part where it inserts inside the database which I think has the actual error with regards to the image being inserted.</p>
  
  <pre><code> public void onCreate(SQLiteDatabase db) {
      String createTable="CREATE TABLE "+ TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT , "
              + FN + " TEXT , "
              + LN + " TEXT ,"
              + E_M + " TEXT ,"
              + PASS + " TEXT ,"
              + Mobnum + " INTEGER, "
              + image + " BLOB)";
      db.execSQL(createTable);
  
  }
  
  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
      onCreate(db);
  
  }
  public boolean addData(String FirstName,String LastName,String Email,String Password,String MobileNumber, byte[] Profileimg) //to write into the datbase
  {
      SQLiteDatabase db = this.getWritableDatabase();
      ContentValues cv =new ContentValues();
      cv.put(FN,FirstName);
      cv.put(LN,LastName);
      cv.put(E_M,Email);
      cv.put(PASS,Password);
      cv.put(Mobnum,MobileNumber);
      cv.put(image, Profileimg);
  
      Log.d(DATABASE_NAME,"adding : " + FirstName + " TO " + TABLE_NAME );
      long result=db.insert(TABLE_NAME,null,cv);
      //if  the result inserted correctly or not
      if(result==-1)
      {
          return false;
      }
      else
      {
          return true;
      }
  }
  </code></pre>
  
  <p>I got these 2 functions online so I think it's important to put them here but I think they've something to do with the error but I can't be sure</p>
  
  <pre><code>    private void dispatchTakePictureIntent() {
      Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
      if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
          startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
      }
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == RESULT_OK) {
          Bitmap photo = (Bitmap) data.getExtras().get("data");
          img.setImageBitmap(photo);
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
          byteArray = stream.toByteArray();
      }
  }
  </code></pre>