title: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference, iven that object is not null and initialize
body: <p>i know that quastion has asked lot of times, but im realy dont found solution.
  i know the error come couse the object intent is null, but how? if i choose a picture from a gallery?
  this is the the error i get</p>
  
  <pre><code>    E/Volley: [497] NetworkDispatcher.processRequest: Unhandled exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
      java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
          at java.net.URLEncoder.encode(URLEncoder.java:205)
          at com.android.volley.Request.encodeParameters(Request.java:491)
          at com.android.volley.Request.getBody(Request.java:477)
          at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:245)
          at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:219)
          at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:97)
          at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
          at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
          at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
  D/EGL_emulation: eglMakeCurrent: 0xa7685060: ver 3 1 (tinfo 0xa7683280)
  D/EGL_emulation: eglMakeCurrent: 0xa7685060: ver 3 1 (tinfo 0xa7683280)
  </code></pre>
  
  <p>this is my intent object part:</p>
  
  <pre><code>btnSelectImage.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Dexter.withActivity(uploadimage.this).withPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                      .withListener(new PermissionListener() {
                          @Override
                          public void onPermissionGranted(PermissionGrantedResponse response) {
                              Intent intent = new Intent(Intent.ACTION_PICK);
                              intent.setType("image/*");
                              startActivityForResult(Intent.createChooser(intent,"Select image"),1);
                          }
  </code></pre>
  
  <p>when i came to this part of the code, its fall, couse intent is null? but why is like that?</p>
  
  <pre><code> protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
      if(requestCode==1 &amp;&amp; requestCode==RESULT_OK &amp;&amp; data!= null){
          Uri filePath = data.getData();
          try {
              InputStream inputStream = getContentResolver().openInputStream(filePath);
              bitmap = BitmapFactory.decodeStream(inputStream);
              imageView.setImageBitmap(bitmap);
              imageStore(bitmap);
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
  
      }
      super.onActivityResult(requestCode, resultCode, data);
  
  }
  </code></pre>
  
  <p>what can be the problem?
  i add to manifest the permission of READ_EXTERNAL_STORAGE .</p>
  
  <p>this is all my code, if its relevant.</p>
  
  <pre><code>    package com.example.yacovapp;
  import android.Manifest;
  import android.app.ProgressDialog;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.net.Uri;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.provider.MediaStore;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageView;
  import androidx.annotation.Nullable;
  import androidx.appcompat.app.AppCompatActivity;
  import com.android.volley.toolbox.StringRequest;
  import android.widget.Toast;
  import com.android.volley.AuthFailureError;
  import com.android.volley.Request;
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.Volley;
  import com.karumi.dexter.Dexter;
  import com.karumi.dexter.PermissionToken;
  import com.karumi.dexter.listener.PermissionDeniedResponse;
  import com.karumi.dexter.listener.PermissionGrantedResponse;
  import com.karumi.dexter.listener.PermissionRequest;
  import com.karumi.dexter.listener.single.PermissionListener;
  
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStream;
  import java.util.Map;
  import java.io.ByteArrayOutputStream;
  import java.util.HashMap;
  import android.util.Base64;
  
  public class uploadimage extends AppCompatActivity {
  
      Button btnSelectImage, btnUploadImage;
      ImageView imageView;
      Bitmap bitmap;
      String encodedImage;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_uploadimage);
  
          btnSelectImage = (Button) findViewById(R.id.btnSelectImage);
          btnUploadImage = (Button) findViewById(R.id.buttonUploadImage);
          imageView = findViewById(R.id.imView);
  
          btnSelectImage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Dexter.withActivity(uploadimage.this).withPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
                          .withListener(new PermissionListener() {
                              @Override
                              public void onPermissionGranted(PermissionGrantedResponse response) {
                                  Intent intent = new Intent(Intent.ACTION_PICK);
                                  intent.setType("image/*");
                                  startActivityForResult(Intent.createChooser(intent,"Select image"),1);
                              }
                              @Override
                              public void onPermissionDenied(PermissionDeniedResponse response) { }
  
                              @Override
                              public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) { }
                          }).check();
              }
          });
  
          btnUploadImage.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  StringRequest request = new StringRequest(Request.Method.POST, "https://kerron.xyz/htdocs/images.php"
                          , new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
                          Toast.makeText(uploadimage.this, response, Toast.LENGTH_SHORT).show();
                      }
                  }, new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          Toast.makeText(uploadimage.this, error.getMessage(), Toast.LENGTH_SHORT).show();
                      }
                  }){
                      @Override
                      protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                          Map &lt;String, String&gt; param = new HashMap&lt;&gt;();
                          param.put("image", encodedImage);
                          return param;
                      }
                  };
                  RequestQueue requestQueue = Volley.newRequestQueue(uploadimage.this);
                  requestQueue.add(request);
              }
          });
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          if(requestCode==1 &amp;&amp; requestCode==RESULT_OK &amp;&amp; data!= null){
              Uri filePath = data.getData();
              try {
                  InputStream inputStream = getContentResolver().openInputStream(filePath);
                  bitmap = BitmapFactory.decodeStream(inputStream);
                  imageView.setImageBitmap(bitmap);
                  imageStore(bitmap);
  
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              }
  
          }
          super.onActivityResult(requestCode, resultCode, data);
  
      }
  
      private void imageStore(Bitmap bitmap) {
          ByteArrayOutputStream stream = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  
          byte [] imageBytes = stream.toByteArray();
          encodedImage = android.util.Base64.encodeToString(imageBytes,Base64.DEFAULT);
      }
  }
  </code></pre>
  
  <p>php file: (on server in the folder of public_html i create a folder htdocs and in this folder i have all my php files of the project)</p>
  
  <pre><code>    &lt;?php
  $conn = mysqli_connect("78.140.191.36","kerronxy_yacov", "]k2oIl?WBRPh", "kerronxy_users");
  
  if(isset($_POST['image'])) {
  
      $target_dir = "htdocs/";
      $image = $_POST['image'];
      $imageStore = rand()."_".time()."jpeg";
      $target_dir = $target_dir."/".$imageStore;
      file_put_contents($target_dir, base64_decode($image));
  
      $select = "INSERT INTO images (image) VALUES ($imageStore)";
      $responce = mysqli_query($conn, $select);
  
      if($responce) {
  echo "Image Uploaded";
  mysqli_close($conn);
      }
  
  }
  </code></pre>