We help IT Professionals succeed at work.

1 error

basgen
basgen asked
on
263 Views
Last Modified: 2010-03-31
hi there, I am getting an error here. Could someone help me check it out. thanks. here is the program and the error respectively.

public class Calendar {
  private static Date today;
  public static Date getDate() {
    return today;
   
   
   
    static{date1 = 01012005();    
    for(int cnt = 0; cnt < var2; cnt++){      var3 += var1;
       } //end for loop    
       System.out.println("End first static init: "                                   ());  
       }; //end first static initializer block
      
  }
  public static void tock(int days) {
  }
}



this is the error...

--------------------Configuration: <Default>--------------------
C:\Calendar.java:8: illegal start of expression
    static{date1 = 01012005();    
    ^
1 error

Process completed.
Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Put the static block outside of the getDate() method
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
public class Calendar {
  private static Date today;

  static{date1 = 01012005();    
    for(int cnt = 0; cnt < var2; cnt++){      var3 += var1;
       } //end for loop    
       System.out.println("End first static init: "                                   ());  
       }; //end first static initializer block

  public static Date getDate() {
    return today;
   
     
     
  }
  public static void tock(int days) {
  }
}
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
BTW you will need to declare the "varx", the "date1" and the "cnt" variables.

Author

Commented:
hmm i dont get you...how does the varx work? and the date1 and cnt?
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You need to declare these variable somewhere in order to use them, otehrwise you will be getting error messages. Have a look here for more info: http://java.sun.com/docs/books/tutorial/java/javaOO/variables.html

Author

Commented:
okie noted but where does these error msges go?
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Is this a typing mistake or do you really dont have a closing bracket after the "return today;" statement?

Author

Commented:
okie, where does the class files go?
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
I think you should start from the very basic: http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
> Is this a typing mistake or do you really dont have a closing bracket after the "return today;" statement?

There is if you move the static initializer outside the method.
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
>> System.out.println("End first static init: "                                   ());  

Remove the extra () there.

Author

Commented:
does not seem to work la...the static is a prob still
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
The static is fine, you are probably getting another error. Please post it.

Author

Commented:
okie..do u have an email address? ill send u the questions..u have a look.think that wld be better
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Sorry, not allowed ot help via e-mail, please post here. I need

a) the source code of the file where the error occurs
b) The error messages you are getting when you try to compile the java file
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
>> }; //end first static initializer block

The semi-colon there is not required.
Mayank SPrincipal Technologist
CERTIFIED EXPERT

Commented:
What was the problem and what was the solution?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.