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 trialMichael LaCroix
5,828 PointsJava import issues in Android SDK
I've had an error pop up a few times concerning Java imports when I copy and paste a chunk of code into a new class (usually one we've created). It seems to resolve itself when I click import but I'd like to know why I have this error and he doesn't. Error posted below -
The code fragment which you have pasted uses classes that are not accessible by imports in the new context. Select classes that you want to import to the new file.
- java.util.Random
2 Answers
J.D. Sandifer
18,813 PointsI wanted to mention that this error is really just Android Studio taking care of things for you. I actually like knowing what it's doing for me so I realize what I'd need to do if I were coding from scratch in a text editor.
If you prefer not to see the messages, though, Peter's solution should take care of it for you:
"If you go to File > Settings then search for "auto import" you'll see a way to change the behaviour. You can manually navigate there from File > Settings > Editor > Auto Import.
It should be possible to change "Insert imports on paste" to always in order to never see this pop up again."
Salomon Alcoba Trujillo
Courses Plus Student 1,056 Pointsi have the same issue, i get the error i do this "alt + enter" and choose import class, i have many other options, but i need to know why and what this solutions do
Peter Gordon
2,473 PointsPeter Gordon
2,473 PointsI believe that's to do with auto-import and you can change to automatically include the import statements.
If you go to File > Settings then search for "auto import" you'll see a way to change the behaviour. You can manually navigate there from File > Settings > Editor > Auto Import.
It should be possible to change "Insert imports on paste" to always in order to never see this pop up again.