First My application is open MainActivity then i click to button and open problem`s activity
Is my Log
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: FATAL EXCEPTION: main
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: Process: tj.tajdev.mrking.whatisonindushanbe, PID: 27694
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: java.lang.NullPointerException: file
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at android.net.Uri.fromFile(Uri.java:452)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at tj.tajdev.mrking.whatisonindushanbe.AdderProduct.AdderActivity2.getOutputMediaFileUri(AdderActivity2.java:222)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at tj.tajdev.mrking.whatisonindushanbe.AdderProduct.AdderActivity2.captureImage(AdderActivity2.java:107)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at tj.tajdev.mrking.whatisonindushanbe.AdderProduct.AdderActivity2.access$000(AdderActivity2.java:22)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at tj.tajdev.mrking.whatisonindushanbe.AdderProduct.AdderActivity2$1.onClick(AdderActivity2.java:61)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at android.view.View.performClick(View.java:5204)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:21153)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-21 18:41:18.947 27694-27694/tj.tajdev.mrking.whatisonindushanbe E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
My Activity
public class AdderActivity2 extends Activity {
private static final String TAG = AdderActivity2.class.getSimpleName();
private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;
private static final int CAMERA_CAPTURE_VIDEO_REQUEST_CODE = 200;
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
private Uri fileUri; // file url to store image/video
private Button btnCapturePicture, btnRecordVideo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getResources().getString(R.color.action_bar))));
btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
btnRecordVideo = (Button) findViewById(R.id.btnRecordVideo);
btnRecordVideo.setVisibility(View.INVISIBLE);
btnCapturePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// capture picture
captureImage();
}
});
btnRecordVideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// record video
recordVideo();
}
});
if (!isDeviceSupportCamera()) {
Toast.makeText(getApplicationContext(),
"Sorry! Your device doesn't support camera",
Toast.LENGTH_LONG).show();
// will close the app if the device does't have camera
finish();
}
}
private boolean isDeviceSupportCamera() {
if (getApplicationContext().getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
private void captureImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
}
private void recordVideo() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable("file_uri", fileUri);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
fileUri = savedInstanceState.getParcelable("file_uri");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
launchUploadActivity(true);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(getApplicationContext(),
"User cancelled image capture", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(getApplicationContext(),
"Sorry! Failed to capture image", Toast.LENGTH_SHORT)
.show();
}
} else if (requestCode == CAMERA_CAPTURE_VIDEO_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
launchUploadActivity(false);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(getApplicationContext(),
"User cancelled video recording", Toast.LENGTH_SHORT)
.show();
} else {
// failed to record video
Toast.makeText(getApplicationContext(),
"Sorry! Failed to record video", Toast.LENGTH_SHORT)
.show();
}
}
}
private void launchUploadActivity(boolean isImage){
Intent i = new Intent(AdderActivity2.this, UploadActivity.class);
i.putExtra("filePath", fileUri.getPath());
i.putExtra("isImage", isImage);
startActivity(i);
}
public Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
private static File getOutputMediaFile(int type) {
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
Config.IMAGE_DIRECTORY_NAME);
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.d(TAG, "Oops! Failed create "
+ Config.IMAGE_DIRECTORY_NAME + " directory");
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
File mediaFile;
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "IMG_" + timeStamp + ".jpg");
} else if (type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "VID_" + timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;
}
}
how to fix it? My application capture image and send to server please help, help Permision is true. What is my mistake ? Mybe problem with them of it activity? and php code too is true