title: How to pass image path as parameter for an image to be taken from camera
body: <p>I am passing Image as parameter in this function:</p>
  
  <p>twitt.shareToTwitter(string_msg, casted_image);
  <strong>(void chintan.khetiya.android.Twitter_code.Twitt_Sharing.shareToTwitter(String msg, File Image_url))</strong></p>
  
  <p>Now here I am selecting image from gallery, but now I want to take pic from cam and pass it. How to do it.?</p>
  
  <p>Here is the full code:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  // Replace your KEY here and Run ,
  public final String consumer_key = "trWwomp0b09ER2A8H1cQg";
  public final String secret_key = "PAC3E3CtcPcTuPl9VpCuzY6eDD8hPZPwp6gRDCviLs";
  File casted_image;
  
  String string_img_url = null, string_msg = null;
  Button btn, pick, cam;
  EditText et;
  ImageView iv;
  private static int RESULT_LOAD_IMAGE = 1;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      try {
          setContentView(R.layout.main);
  
          iv = (ImageView) findViewById(R.id.imageView1);
  
          pick = (Button) findViewById(R.id.button1);
          pick.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent i = new Intent(
                          Intent.ACTION_PICK,
                          android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
                  startActivityForResult(i, 1);
              }
          });
  
          cam = (Button) findViewById(R.id.button2);
          cam.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Intent takePicture = new Intent(
                          MediaStore.ACTION_IMAGE_CAPTURE);
                  startActivityForResult(takePicture, 0);
              }
          });
  
          btn = (Button) findViewById(R.id.btn);
          btn.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  onClickTwitt();
              }
          });
      } catch (Exception e) {
          // TODO: handle exception
          runOnUiThread(new Runnable() {
              public void run() {
                  showToast("View problem");
              }
          });
  
      }
  }
  
  public void Call_My_Blog(View v) {
      Intent intent = new Intent(MainActivity.this, My_Blog.class);
      startActivity(intent);
  
  }
  
  // Here you can pass the string message &amp; image path which you want to share
  // in Twitter.
  public void onClickTwitt() {
      if (isNetworkAvailable()) {
          Twitt_Sharing twitt = new Twitt_Sharing(MainActivity.this,
                  consumer_key, secret_key);
  
          et = (EditText) findViewById(R.id.editText1);
          string_msg = et.getText().toString();
  
          twitt.shareToTwitter(string_msg, casted_image);
  
      } else {
          showToast("No Network Connection Available !!!");
      }
  }
  
  // when user will click on twitte then first that will check that is
  // internet exist or not
  public boolean isNetworkAvailable() {
      ConnectivityManager connectivity = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
      if (connectivity == null) {
          return false;
      } else {
          NetworkInfo[] info = connectivity.getAllNetworkInfo();
          if (info != null) {
              for (int i = 0; i &lt; info.length; i++) {
                  if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                      return true;
                  }
              }
          }
      }
      return false;
  }
  
  private void showToast(String msg) {
      Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
  
  }
  
  protected void onActivityResult(int requestCode, int resultCode,
          Intent imageReturnedIntent) {
      super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
  
      switch (requestCode) {
      case 0:
          if (resultCode == RESULT_OK) {
              Uri selectedImage = imageReturnedIntent.getData();
              String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
              Cursor cursor = getContentResolver().query(selectedImage,
                      filePathColumn, null, null, null);
              cursor.moveToFirst();
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              // file path of captured image
              String filePath = cursor.getString(columnIndex);
              // file path of captured image
              casted_image = new File(filePath);
  
          }
          break;
      case 1:
          if (requestCode == 1 &amp;&amp; resultCode == RESULT_OK
                  &amp;&amp; null != imageReturnedIntent) {
              Uri selectedImage = imageReturnedIntent.getData();
              String[] filePathColumn = { MediaStore.Images.Media.DATA };
  
              Cursor cursor = getContentResolver().query(selectedImage,
                      filePathColumn, null, null, null);
              cursor.moveToFirst();
  
              int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
              String picturePath = cursor.getString(columnIndex);
              casted_image = new File(picturePath);
              cursor.close();
              iv.setImageURI(selectedImage);
              // String picturePath contains the path of selected Image
              break;
          }
      }
  }
  }
  </code></pre>
  
  <p><strong>Log.txt:</strong></p>
  
  <pre><code>09-10 16:42:26.672: E/AndroidRuntime(1888): FATAL EXCEPTION: main
  09-10 16:42:26.672: E/AndroidRuntime(1888): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data (has extras) }} to activity {chintan.khetiya.android.Twitter_sharing/chintan.khetiya.android.Twitter_sharing.MainActivity}: java.lang.NullPointerException
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:2574)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.app.ActivityThread.access$2000(ActivityThread.java:117)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:961)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.os.Handler.dispatchMessage(Handler.java:99)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.os.Looper.loop(Looper.java:123)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.app.ActivityThread.main(ActivityThread.java:3683)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at java.lang.reflect.Method.invokeNative(Native Method)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at java.lang.reflect.Method.invoke(Method.java:507)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at dalvik.system.NativeStart.main(Native Method)
  09-10 16:42:26.672: E/AndroidRuntime(1888): Caused by: java.lang.NullPointerException
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.content.ContentResolver.acquireProvider(ContentResolver.java:743)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.content.ContentResolver.query(ContentResolver.java:256)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at chintan.khetiya.android.Twitter_sharing.MainActivity.onActivityResult(MainActivity.java:155)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.app.Activity.dispatchActivityResult(Activity.java:3908)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
  09-10 16:42:26.672: E/AndroidRuntime(1888):     ... 11 more
  </code></pre>