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 trial

Android Build a Simple Android App (2014) Basic Android Programming Generating a Random Number

Sara Grim
Sara Grim
5,285 Points

After running the program, I get "cannot resolve the symbol class Random & cannot resolve method 'next.Int (int)'.

What should I do to resolve the Random alerts after coding for the random numbers?

Sara Grim
Sara Grim
5,285 Points

I am using the Android Studio for "Fun Facts Activity". ```Javascript String fact = ""; Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(3); fact = randomNumber + "";

When I run the program, it cannot resolve the symbol class Random and the method 'next.Int(int)'.
What should I do?

3 Answers

Stone Preston
Stone Preston
42,016 Points

when typing methods and classnames, when you choose the autocomplete value android studio automatically imports the class if needed. If you dont use the autocomplete value, then you have to import it yourself. you must not have used the autocomplete value when typing Random. to fix this, just import the Random class by adding this to the top of your file below the package declaration

import java.util.Random;
Sara Grim
Sara Grim
5,285 Points

Thank you Stone. It worked! Where is the autocomplete, so I can use it?

Stone Preston
Stone Preston
42,016 Points

autocomplete is just the box that comes up whenever you are typing code. it recognizes what you are typing and shows suggestions. It should be on automatically, but if not you can enable it in your editor preferences

Alvaro Gutierrez
Alvaro Gutierrez
1,471 Points

I just used the auto complete and it resolve my issue. Thanks!

Twinnie Ting
PLUS
Twinnie Ting
Courses Plus Student 2,441 Points

Just to add: to autocomplete in MAC - hover your mouse cursor to the small pop up box and then click - Alt + enter, it would then autocomplete.

Twinnie Ting
PLUS
Twinnie Ting
Courses Plus Student 2,441 Points

Just to add: to autocomplete in MAC - hover your mouse cursor to the small pop up box and then click - Alt + enter, it would then autocomplete.