176 CHAPTER 6: Android Screen Design: Writing to the Display Using Activity and View
As you can see in Figure 6-6, when you type this in Eclipse, the IDE will check your Galaxy.java
class method.
Figure 6-6. Constructing a Galaxy object named milkyWay using a Java new keyword and a Galaxy( ) constructor method
I typed the constructor method call in this incomplete way to show you that your Galaxy.java class
is now a part of all of the Java language constructs that Eclipse checks all code against, and Eclipse
will now tell you that you are not calling your constructor method correctly, and an error underline
now highlights this new Galaxy( ) method call!
When you mouse-over the error highlight, you will get a light yellow coding tips popup, which will
tell you what Eclipse thinks is wrong with your Java code; in this case, “The constructor Galaxy( )
is undefined” or more accurately, the constructor method call is not defined (configured) correctly.
Eclipse is even nice enough to suggest “quick fixes” and as you can see the first one shows your
constructor method call format of Galaxy(String, int, int), which tells you that you need to pass
some data values over inside of the method call parens (parameters area).
Let’s add a galaxy name, number of solar systems, and number of inhabited planets now, and
see if this removes the error. As you can see in Figure 6-7, I added the String “Milky Way,” 511
solar systems, and 97 habitable planets to the constructor method call, and this removed the red
error highlighting, but added some yellow warning highlighting. A warning means that the code
will compile and run, whereas the error means that the code will not even allow you to attempt to
compile (and run) your application until you fix that particular programming problem.