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!
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 trial
The 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
Ratik Sharma32,885 Points
You 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!
During 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.
When 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?
Goran Penov1,635 Points
I have the same problem and java.util.Random automatically placed the import for me. Still got the errors.