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
Tod Grobey
308 PointsObjects and Random Numbers randomGenerator error
I'm following the lessons for Crystal Ball. I pause the video to make sure I do things right and double check. Eclipse showed me an error on randomGenerator. In the video @ 4 minutes in, code line 31 we are adding
31 int randomNumber = randomGenerator
and upon typing the period Intellisense will not pop up, because randomGenerator is underlined in red. Intellisense gave about 4 options when hovering over randomGenerator, which I do not have anymore because I clicked one and, alas, I know not which. But I recall Eclipse somehow did not know what randomGenerator was. So here can I learn if it should be a variable, or parameter, or exactly what? Because the terminology is ramping up fast. Codepen.io link? http://cdpn.io/fELxJ
9 Answers
Ernest Grzybowski
Treehouse Project ReviewerIncorrect:
int randomNum = randomGenerator.nextInt();
Random randomGenerator = new Random();
Correct:
Random randomGenerator = new Random();
int randomNum = randomGenerator.nextInt();
Also, please paste your code.
Ernest Grzybowski
Treehouse Project ReviewerAt 2:57 you declare:
Random randomGenerator = new Random();
Did you do that?
Also, make sure that your int declaration is below the declaration of randomGenerator.
Tod Grobey
308 PointsYes, I did. :)
Tod Grobey
308 PointsThanks for your help & patience, Ernest. I'm very new at this.
I tried to learn the right way to paste the code so that it shows as yours does, but as you can see I failed there. Any tips are appreciated.
I finally figured out what I'd done to confuse Eclipse! Just a small typo. Now I know what I'll be checking first when an error appears.
Cheers!
Ernest Grzybowski
Treehouse Project ReviewerYep! Typos seem to be the biggest mistake for people that are new to programming. Once you make your first typo, you seem to always check for a typo if you ever get any other errors.
Ben Jakuben
Treehouse Teacher@Ernest, !
@Tod, to paste in code, you can do one of two things. The forum posts are based on Markdown (there's a link to a cheat sheet at the bottom of each forum page).
Indent each line by four spaces
Surround your code with three backticks and "java" on the line before it and three backticks on the line below it, like this:
```java
String test = "This is a test";
```
String test = "This is a test";
Tod Grobey
308 Points@ Ben, Thanks! That really helped. I think that should be one a featured post to help a newbie. If I compare your nice example to the cheatsheet below, I think the one below presumes a certain level of experience, and that's why a newbie like me did not manage as well.
Feedback idea for the site: a quick lexicon of Java that includes super basic things coding needs, like the definition of 'object' and 'class' and 'method'. And also it would include a common syntax usage with arrows that label each aspect of the code. I'm a language teacher, so it is very much like the basic sentence structure of a particular language [subject + verb + adverb + direct object + adjective]. My arrows would tell you that 'adjective' = describes the noun, and 'verb' = is the main activity related to the subject. Yours would point to 'String' = a grouping of text, 'name' = the name you give this string, etc.
I think that helps autodidacts (self learners) really grapple with the concepts and then improve. Keep up the good work!
Ben Jakuben
Treehouse TeacherThanks for the feedback! We would like to add a deep dive about Java at some point in the future. In the meantime, I wrote two blog posts about Java basics for Android development that help to further explain the language constructs. Check them out and let me know if they help or if you have additional feedback!
These links are also included in notes on the video page, but they can be easy to miss.
Ernest Grzybowski
Treehouse Project ReviewerHey Tod,
In addition to those blog posts by Ben (which are great btw) I would recomend this series: http://teamtreehouse.com/library/programming/introduction-to-programming
Also, check this out:
http://commonsware.com/blog/2010/08/02/java-good-parts-version.html
"Every now and again, people ask me what portions of Java one needs to know to be effective in Android."
"If you are in need of a crash course in Java to get involved in Android development, here are the concepts I would focus upon, with links to relevant sections of the Java Wikibook:"