title: converting bitmap image works in activity but generates null reference error on fragment
body: <p>Converting bitmap to string and compressing bitmap is worked fine in activity but in fragment activity, it generates null object reference error</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                    Process: com.news.androidapp, PID: 5777
                    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference
                        at com.news.androidapp.News_Yeb.convertBitmapToString(News_Yeb.java:161)
                        at com.news.androidapp.News_Yeb.onClick(News_Yeb.java:110)
  </code></pre>
  
  <p>Extending Fragment</p>
  
  <pre><code>public class News_Yeb extends Fragment implements OnClickListener {
      Button bt_register;
      TextInputLayout til_name;
      ImageView iv_profile;
      String name, profile;
      RequestQueue requestQueue;
      boolean IMAGE_STATUS = false;
      Bitmap profilePicture;
      View view;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.news_yeb, container, false);
          til_name = view.findViewById(R.id.til_name_reg);
          iv_profile = view.findViewById(R.id.im_profile);
          bt_register = view.findViewById(R.id.bt_register);
  
          iv_profile.setOnClickListener(this);
          bt_register.setOnClickListener(this);
  
          return view;
      }
  </code></pre>
  
  <p>Adding two onClick event using switch case, one is for imageview and another is for submit button</p>
  
  <pre><code>@Override
  public void onClick(View view) {
      switch (view.getId()) {
          case R.id.im_profile:
  
          Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
          intent.setType("image/*");
          startActivityForResult(intent, 1000);
              break;
  
          case R.id.bt_register:
              name = til_name.getEditText().getText().toString();
              if (     validateName(name)       )
  
              {
           final ProgressDialog progress = new ProgressDialog(getActivity());
                  progress.setTitle("Please Wait");
                  progress.setMessage("Creating Your Account");
                  progress.setCancelable(false);
                  progress.show();
                  convertBitmapToString(profilePicture);
                  RegisterRequest registerRequest = new RegisterRequest(name, profile, new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          Log.i("Response", response);
                          progress.dismiss();
                          try {
                              if (new JSONObject(response).getBoolean("success")) {
                                  Toast.makeText(getActivity().getApplicationContext(), "Account Successfully Created", Toast.LENGTH_SHORT).show();
                                  finish();
                              } else
                                  Toast.makeText(getActivity().getApplicationContext(), "Something Has Happened. Please Try Again!", Toast.LENGTH_SHORT).show();
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
                      }
                  });
                  requestQueue.add(registerRequest);
  
              }
       break;  
      }
  
  }
  </code></pre>
  
  <p>Connecting with PHP/Mysql</p>
  
  <pre><code>public class RegisterRequest extends StringRequest {
  
      private static final String REGISTER_URL = "..";
      private Map&lt;String, String&gt; parameters;
  
      public RegisterRequest(String name, String mobile, String email, String image, Response.Listener&lt;String&gt; listener) {
          super(Method.POST, REGISTER_URL, listener, null);
          parameters = new HashMap&lt;&gt;();
          parameters.put("name", name);
          parameters.put("image", image);
      }
      @Override
      protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
          return parameters;
      }
  }
  </code></pre>
  
  <p>Converting bitmap image into a ByteArrayOutputStream and then converting stream into a byte array</p>
  
  <pre><code>private void convertBitmapToString(Bitmap profilePicture) {
      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
      profilePicture.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
      byte[] array = byteArrayOutputStream.toByteArray();
      profile = Base64.encodeToString(array, Base64.DEFAULT);
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == 1000 &amp;&amp; resultCode == Activity.RESULT_OK &amp;&amp; data != null) {
          //Image Successfully Selected
          try {
              //parsing the Intent data and displaying it in the imageview
              Uri imageUri = data.getData();//Geting uri of the data
  
                      InputStream imageStream = getActivity().getApplicationContext().getContentResolver().openInputStream(imageUri);//creating an imputstrea
              profilePicture = BitmapFactory.decodeStream(imageStream);//decoding the input stream to bitmap
              iv_profile.setImageBitmap(profilePicture);
              IMAGE_STATUS = true;//setting the flag
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>