title: Android: Byte array for the image is null when stored in SQLite
body: <p>I am very close to having this work. I get a picture from the camera and store it in my SQLite database. However when I store it, I get this error. The byte array for the image is null when stored. Why? How can I fix it?</p>
  
  <blockquote>
    <p>E/AndroidRuntime: FATAL EXCEPTION: main
                      Process: com.example.psa.stepbystep, PID: 16363
                      java.lang.NullPointerException: Attempt to get length of null array
                          at com.example.psa.stepbystep.Walk.writeToParcel(Walk.java:161)
                          at android.os.Parcel.writeParcelable(Parcel.java:1730)
                          at android.os.Parcel.writeValue(Parcel.java:1636)
                          at android.os.Parcel.writeArrayMapInternal(Parcel.java:777)
                          at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506)</p>
  </blockquote>
  
  <p>Walk Activity contains Parcel</p>
  
  <pre><code>public Walk(Parcel in) {
          this._photo = new byte[in.readInt()];
          in.readByteArray(_photo);
      }
  
  public void writeToParcel(Parcel dest, int flags) {
          dest.writeInt(_photo.length);
          dest.writeByteArray(_photo);
      }
  </code></pre>
  
  <p>WalkPhoto has this to convert </p>
  
  <pre><code> //Convert from bitmap to byte array
      public static byte[] getBytes(Bitmap bitmap) {
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
          return stream.toByteArray();
      }
  
      //Convert from byte array to bitmap
      public static Bitmap getImage(byte[] image) {
          return BitmapFactory.decodeByteArray(image, 0, image.length);
      }
  </code></pre>
  
  <p>WalkPhoto also has this to store the image in the database</p>
  
  <pre><code>     if (requestCode == REQUEST_IMAGE_CAPTURE &amp;&amp; resultCode == RESULT_OK) {
              Bundle extras = data.getExtras();
              Bitmap imageBitmap = (Bitmap) extras.get("data");
              ImageView imageview = findViewById(R.id.imageView);
              imageview.setImageBitmap(imageBitmap);
  
              //Bitmap to bytes for database
              byte[] photo = getBytes(imageBitmap);
  
               DatabaseHandler mydb = new DatabaseHandler(getApplicationContext());
  
              Walk walk = new Walk(photo);
  
              mydb.addWalk(walk);
  }
  </code></pre>