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

Completely stuck on Code Challenge: Objects and Random Numbers

so on Code Challenge: Objects and Random Numbers, it asks me to

"Initialize a new Random variable called randomGenerator using the Random() constructor."

i have no idea where to begin, ive re watched the vids and i just dont understand what i need to do :(

help would be greatly appreciated

(p.s. would be nice if the challenges/tests had a hint button)

12 Answers

@Ben Millen

Take a few hours to play around with Android Layouts. The first time I started playing with Android I think I spent like 5 hours just using different layouts and trying to create different things with them.

Try to create a:

  • Signup form
  • Calculator
  • Dashboard
  • Chat client

You don't have to program those... just try to create them. You'll be surprised at how much trouble you'll probably have and how many options you have/what's the best option.

Here's a great way to take a look at your layouts, to make sure they are efficient.

http://www.curious-creature.org/2012/12/06/android-performance-in-practice/

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

@Ernest: +1 for the Romain Guy article! :smiley:

I have never watched this course, and i have never done any Java - But managed to do the challenge based on the information i know about object oriented programming.

Take a look at the "Reading material" for that video. And take a note about what he is saying! If you are new to Object oriented programming - Have a look at the link he pasted in the description. That should give you a good pointer on how you instantiate new objects e.e

Take a look at the API that is mentioned in the description aswell.

There are a total of 3 lines of code for that codechallenge. And if you look at the description of each task. they basicly tell you exactly what to do.

  • i Could give you the answer to the code challenge - But this is something you have to understand, its really fundamental. And just think about the feeling of accomplishment after you finished on your own ;)

Thank you Christer, annoyingly i figured it out shortly after posting :/ im a complete newb to any sort of programming language so its all a little slow to sink in, i think i may end up doing each course several times to take it in fully.

thank you for taking the time to answer....i suspect there may be more questions to come :)

Great! :) Best of luck! I have no idea what level that android development course is aimed at, so best of luck to you :)

If you want to get into Object oriented programming in a more in-depth way (Aimed for beginners) - Have a look at the Stanford CS106A on iTunes U:

https://itunes.apple.com/no/course/programming-methodology/id495054181?l=nb

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi @Ben,

Sorry you're having trouble! The Crystal Ball course is aimed at total beginners, but I imagine it would take some re-watching and extra reading for people who are totally new to programming. Check out the "Objects and Random Numbers" video around the 3:00 mark to see where I'm talking about instantiating objects. Also, the code in these challenges is usually pretty similar to code we cover in the videos, so you could always pause the videos and study the code or download the project files (link below the video) and take a look at the code for similarities.

A hint button is a good idea. I think that may be on our idea list of enhancements.

Let me know if you have any trouble or feedback as you continue with the course. Please stick with it as I'm sure things will start to click as you keep practicing! The course gets into a little more complex programming as you progress, but I explain every line and word and even if it doesn't make sense the first time, it should sink in with review and practice.

ah wow the teacher himself :) thanks, yeah its taking a while to wrap my head around but so far its great and the way teamtreehouse lessons are set out (with the tests and exercises inbetween) is ideal for me as my brain immediatly switches off when confronted with a wall of text to read. i shall indeed continue as i have several good app ideas i just need to know how to make them :)

Thanks

ok i have another question (wasnt sure if i should start a new post)

so im up to here... "Android Development > Build a Simple Android App > Pretty Little Things > Positioning Text Using a Linear Layout"

now ill admit im straying from the original design, im using a different picture and the crystal ball is smaller and slightly to the left bottom of the screen

how do i position the text,layout,view etc if i dont want it central

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Cool - glad you're experimenting!

So we are using a RelativeLayout, meaning that everything inside needs to be relative to the layout borders or something else inside the layout. What you probably want to set first are the "layout alignment" properties. Select the TextView or whatever in the Graphical Layout editor, and then in the Properties pane, expand "Layout Parameters." There are a group that begin with "Align" that allow you to align to the parent (the RelativeLayout itself) or to other items by their IDs.

You can also center and set margins by expanding "Margins" to hopefully get things right where you want them.

For a full list of parameters you can look at the documentation for RelativeLayout.

If this isn't enough information, post more specific questions in here and I or other members can hopefully help.

Thanks peeps. Ill have a play :)

"Declare a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable. Hint: Use the toString() method of the Integer class."

I hit a wall on this one, if anyone has anything to hint, please do.

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Hi @Robert,

I'm assuming you have

String intAsString =

to start. From there, you just need to figure out what goes on the right side of the equation to convert randomNumber from an int to a String. This is covered toward the end of the video, but you can also check out the Integer class documentation for the toString(int i) method. That documentation can be a little obtuse, but the method takes an int as a parameter. It's a static method, meaning that it can be called with just the class name in front of it as opposed to a whole variable of that type.

Hope this helps! In the future, go ahead and open a new question in the forum when asking about something different than the original post so that people can find things more easily. This forum is slowly becoming (by design) a repository for tips and hints about our code challenges and quizzes.