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 trialKimberly Hoshal
645 PointsThe code fragment you pasted uses classes that are not accessible by imports in new context. Not sure what happened.
The above message appeared when I tried to paste the code from the FunFact to the FactBook. It wants me to select a class to import to the new file. They give the choice java.util.Random
6 Answers
Ratik Sharma
32,885 PointsThis could just be because of Auto Import in Android Studio off. Use this to enable it: http://stackoverflow.com/a/16616085 and hopefully things will import automatically when copy-pasting.
Gunjeet Hattar
14,483 PointsI tried doing the same and it automatically places the import for me. Maybe some default setting for auto import might have been turned off.
Just check that from the link here IntelliJ Auto Import
Ratik Sharma
32,885 PointsYou need to import java.util.Random It's required for the project. If that's not your problem, please elaborate and I'll help you out!
Gunjeet Hattar
14,483 PointsDuring simple refactoring, you would have copied the section along with the Random declaration from FunFactsActivity file into a new file called FactBook. It was a simple copy paste procedure. However, when you did that and ran the program, the class FactBook lost track of Random class since it was not imported like it was in FunFactsActivity file. For Random to be used we have to implicitly import it. Rest Ratik's answer is completely justified else if its some other reason as pointed out.
Kimberly Hoshal
645 PointsI guess my big confusion is that when Ben copied and pasted the same code, he did not get this warning. I studied the video and did exactly the same thing. What would be the difference? Still do not understand. Just a note: this is my first ever app class.
Gunjeet Hattar
14,483 PointsWhen Ben copy pasted the code from one file to the other intelliJ (thus Android Studio) was smart enough to import the Random file itself.
Maybe its an IDE issue. Are you Eclipse or Android Studio?
Kimberly Hoshal
645 PointsAndroid Studio. It just happened again when pasting to the ColorWheel.
Goran Penov
1,635 PointsI have the same problem and java.util.Random automatically placed the import for me. Still got the errors.
Ratik Sharma
32,885 PointsSometimes cleaning and rebuilding the project helps. Go to Build -> Rebuild project or Clean Project
ameydharden
3,329 PointsI had this issue too, so I checked the forum to see if this was something I needed to correct before moving on. I took Ratik's suggestion to clean the project--and it appears that cleaning it deleted the FactBook class that we just created? I can't seem to find it. Rebuilding it didn't put it back, as far as I can see.
Slava Fleer
6,086 PointsSlava Fleer
6,086 Pointsthanks it's still not exactly like in video. it adding import line for random and not green in package. hope it is not important. would be nice to know why the difference ;)