Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Self-Destructing Message Android App Capturing Photos and Videos Setting Where Photos are Saved

Wei-Ting Chen
Wei-Ting Chen
7,632 Points

can not resolve constructor 'Date()'

Hi everyone, I followed the instruction of this course but there is an error shows "can not resolve constructor 'Date()'". Where did I do wrongly?

``Android

   public void onClick(DialogInterface dialog, int which) {
        switch (which){
            case 0:
                Intent takePhotoIntent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                mMediaUri=getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
                if(mMediaUri==null){
                    Toast.makeText(MainActivity.this,R.string.error_external_storage,Toast.LENGTH_LONG).show();
                }
                else {
                    takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
                    startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
                }
                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
        }
   }
   private Uri getOutputMediaFileUri(int mediaTypeImage) {

       if(isExternalStorageAvailable()){


           String appName=MainActivity.this.getString(R.string.app_name);
           File mediaStorageDir =new File(
                   Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),appName);

            if(! mediaStorageDir.exists()){
                if(! mediaStorageDir.mkdirs()){
                    Log.e(TAG,"Failed to create directory");
                    return null;
                }
            }

           File mediaFile;
           Date now=new Date();
           String timestamp=new SimpleDateFormat("yyyyMMdd_HHmmss",Locale.TAIWAN).format(now);

``

Check to see that you imported Date "import java.util.Date;"

Wei-Ting Chen
Wei-Ting Chen
7,632 Points

Thanks!!!! I found out that I imported the "import java.sql.Date;" 謝謝你:)

1 Answer

Vrezh Gulyan
Vrezh Gulyan
11,161 Points

You need to import java.util.date . In general if you are using Android Studio hit alt + enter to get a quick fix and it should automatically import the necessary classes. It also help to use auto complete rather then type out a method when you are following along even though something like date is easy to type. When you use autocomplete it automatically imports the applicable classes along with finishing what you were writing.