Re: Wont compile!!!
On Sat, 10 Nov 2012 16:06:22 -0800 (PST), tyrelmatadin921@gmail.com wrote:
This code will not complile and it is really stressing me out.
If someone could help me out i would really apreciate it. thanks in advanced
There are really a multitude of problems with your code.
PayrollStatement payState = new PayrollStatment();
This creates an infinite loop: every time someone makes an instance of your
class, that instance then executes that line, which makes a new instance,
which then executes that line, which makes a new instance, which then
executes that line, which makes a new instance, which then executes that
line, which makes a new instance, which then executes that line, which
makes a new instance, which then executes that line, which makes a new
instance, which then executes that line, which makes a new instance, which
then executes that line, which makes a new instance, which then executes
that line, which makes a new instance, which then executes that line, which
makes a new instance, which then executes that line, which makes a new
instance, which then executes that line, which makes a new instance, which
then Exception in thread "main" java.lang.StackOverflowError
;)
payState.printEmployeeName();
This is neither a method declaration nor a variable/field declaration. It's
a 'command', and should be inside a method. You can't just randomly litter
method calls and hope they will be executed when you want them to by pure
chance. Odds are you want to put this call in your classes 'main' method -
read up on main methods and how to write one.
payState.isEmpty();
Your method claims to return a boolean, but here you call it and don't do
anything with that boolean. What do you expect to happen with the result ?
public boolean isEmpty();
Here is the method, and the claim that it will at some point return true or
false. It doesn't, however, which is also a critical compile time error. A
method must always return what it claims to return in its signature.
String employeeName;
if (employeeName == true)
StringS cannot be true, they can only be a string or null. As your teacher
told you, StringS have a method to test whether they are empty. Read the
documentation for String and look for that method, like you were told to.
{
System.out.println ("Not entered");
Scanner input = new Scanner(System.in);
String employeeName = input.nextLine();
}
This block does not do what you want it to do. You read in a new String,
but you assign it to a local variable, which is then immediatly discarded
on the next line.
Liebe Gruesse,
Joerg
--
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.