-1

I am doing a simple tutorial for Java using Eclipse and am running into an issue I can't seem to resolve:

package edu.sti.java1;

public class Driver {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println ("This is a Java Program Console Output String!");
    Shout s;
    System.out.println("Are you: "
         + s.getFname()
         + " " + s.getMi()
         +". " + s.getLname()
         + ", " + s.getAge()
         +" YEARS OF AGE?");
    }

}

I get an error that 's' has not been initiated. There are a ton of topics about an integer variable being declared and initiated but I can't seem to find one about assigning a class to a variable. The class 'Shout' appears to be set up properly and is straight from the tutorial.

If anyone can point out my mistake that would be great. If it isn't obvious I am pretty new to programming.

Thanks!

PJM
  • 1
  • 2
  • You *declare* the variable, `Shout s;` but you never *initialize* it, `s = something` -- never assign anything to it. This means that you will want to review or re-review the tutorial on this. Combine whatever tutorial you're using with another often helps. – Hovercraft Full Of Eels Oct 04 '16 at 03:26
  • Save this link: [Big Index](http://docs.oracle.com/javase/tutorial/reallybigindex.html), and start studying from here. – Hovercraft Full Of Eels Oct 04 '16 at 03:27

1 Answers1

0

S needs to be initialized in the following format prior to being used

 Shout s = new Shout(args);

You can look in the shout class to check which arguments it takes in its constructor(function which creates an instance of Shout).

Mr. Negi
  • 154
  • 1
  • 15
  • 1
    Thanks for the response, the previous threads are hard to relate back to something this simple. Using that format, I'm still ending up with an error. I don't really follow the Shout(args) portion, as in what would be inserted there that would be in the 'Shout' class... – PJM Oct 04 '16 at 06:46
  • So in the Shout() you're making a copy of is a java class, just like your Driver Class! Every class which you can make instances of has a method or set of methods called constructors, and each one takes a set of arguments. Any constructor method has the same name as the class. These arguments can be any sort of variable, but are specified by the constructor function in the class you're making an instance of. So the shout s = new Shout(args); is making a new data slot for a Shout instance and then calling Shout's constructor. – Mr. Negi Oct 04 '16 at 23:55
  • To figure out which variables Shout needs to be created, look in the shout class, and find any methods called Shout. These are the possible ways of creating a new instance of shout, and will specify which variable types need to go in the parentheses. – Mr. Negi Oct 04 '16 at 23:56