Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLuke Liem
6,367 Pointscannot find symbol variable mediaStore
I get two errors when compiling the code:
C:\Users\Luke\AStudio082Projects\Rabbit\app\src\main\java\com\scipio\luke\rabbit\MainActivity.java:51: error: cannot find symbol Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); ^ symbol: variable MediaStore Note: C:\Users\Luke\AStudio082Projects\Rabbit\app\src\main\java\com\scipio\luke\rabbit\MainActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\Luke\AStudio082Projects\Rabbit\app\src\main\java\com\scipio\luke\rabbit\FriendsFragment.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
FAILED
FAILURE: Build failed with an exception.
-
What went wrong: Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.555 secs
My MainActivity Code:
C:\Users\Luke\AStudio082Projects\Rabbit\app\src\main\java\com\scipio\luke\rabbit\MainActivity.java:51: error: cannot find symbol Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); ^ symbol: variable MediaStore Note: C:\Users\Luke\AStudio082Projects\Rabbit\app\src\main\java\com\scipio\luke\rabbit\MainActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\Users\Luke\AStudio082Projects\Rabbit\app\src\main\java\com\scipio\luke\rabbit\FriendsFragment.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error
FAILED
FAILURE: Build failed with an exception.
-
What went wrong: Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.555 secs
1 Answer
Luke Liem
6,367 PointsI was able to fix the code by adding the following import statement to MainActivity.java:
import android.provider.MediaStore;
I am using the Android Studio 0.8.6. and it appears that this beta version of AS does not autoimport android.provider.MediaStore when you only have:
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
Though for some strange reason, if you were to have:
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
if (mMediaUri == null) {
Toast.makeText(MyActivity.this, R.string.error_external_storage, Toast.LENGTH_LONG).show();
}
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
Then it will autoimport android.provider.MediaStore.
Luke Liem
6,367 PointsLuke Liem
6,367 PointsMy Code:
package com.scipio.luke.rabbit;
import android.app.ActionBar; import android.app.AlertDialog; import android.app.FragmentTransaction; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewPager; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.Window;
import com.parse.ParseUser;
// MainActivity is extending FragmentActivity instead of Activity // It is also implementing the ActionBar.TabListener interface public class MainActivity extends FragmentActivity implements ActionBar.TabListener {
}