title: How to insert an image into sqlite database?
body: <p>I have tried the following code :</p>
  
  <p>1.Code to convert bitmap to byte array :</p>
  
  <pre><code>private byte[] bitmaptoByteArray( Bitmap bmp)
        {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();
            return byteArray;
        }
  </code></pre>
  
  <p>2.Code which to insert the values into DB</p>
  
  <pre><code>  public void insertIntoImageTable( int companyid , String productname , String productdesc , byte[] bmp )
        {
            ContentValues values = new ContentValues();
              values.put(dataBaseHelper.COMPANY_ID, companyid);           
              values.put(dataBaseHelper.PRODUCT_NAME, productname);
              values.put(dataBaseHelper.PRODUCT_DESCRIPTION, productdesc);
              values.put(dataBaseHelper.PRODUCT_IMAGE, bmp);
              try
              {
                  db.insert(dataBaseHelper.IMAGE_DATA, null, values);
              }
              catch( Exception e)
              {
                  e.printStackTrace();
              }
        }
  </code></pre>
  
  <p>I get nullpointer exception.</p>
  
  <p>Call from the function to put data into DB :</p>
  
  <pre><code>   insertIntoImageTable( 7 , productname[0] , productdesc[0] , barry);
  </code></pre>
  
  <p>All the three bits of code are in the same class file.</p>
  
  <p>Edit: The stack trace is as below.</p>
  
  <pre><code>03-24 16:04:26.245: WARN/System.err(13255): java.lang.NullPointerException
  03-24 16:04:26.265: WARN/System.err(13255):     at com.omkarsoft.ImagePortofolio.sqlQueries.insertIntoImageTable(sqlQueries.java:101)
  03-24 16:04:26.275: WARN/System.err(13255):     at com.omkarsoft.ImagePortofolio.sqlQueries.upLoadtoDatabase(sqlQueries.java:118)
  03-24 16:04:26.305: WARN/System.err(13255):     at com.omkarsoft.ImagePortofolio.ImageAdapter.&lt;init&gt;(ImageAdapter.java:58)
  03-24 16:04:26.315: WARN/System.err(13255):     at com.omkarsoft.ImagePortofolio.imageGridView.onCreate(imageGridView.java:42)
  03-24 16:04:26.335: WARN/System.err(13255):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-24 16:04:26.335: WARN/System.err(13255):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  03-24 16:04:26.355: WARN/System.err(13255):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
  03-24 16:04:26.385: WARN/System.err(13255):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  03-24 16:04:26.385: WARN/System.err(13255):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  03-24 16:04:26.415: WARN/System.err(13255):     at android.os.Handler.dispatchMessage(Handler.java:99)
  03-24 16:04:26.415: WARN/System.err(13255):     at android.os.Looper.loop(Looper.java:123)
  03-24 16:04:26.435: WARN/System.err(13255):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  03-24 16:04:26.445: WARN/System.err(13255):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-24 16:04:26.455: WARN/System.err(13255):     at java.lang.reflect.Method.invoke(Method.java:507)
  03-24 16:04:26.475: WARN/System.err(13255):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  03-24 16:04:26.475: WARN/System.err(13255):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  03-24 16:04:26.505: WARN/System.err(13255):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>