Solved

1 error

Posted on 2006-06-19
18
231 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.
0
Comment
Question by:basgen
  • 9
  • 5
  • 3
  • +1
18 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 16933341
Put the static block outside of the getDate() method
0
 
LVL 35

Expert Comment

by:girionis
ID: 16933346
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) {
  }
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 16933352
BTW you will need to declare the "varx", the "date1" and the "cnt" variables.
0
 

Author Comment

by:basgen
ID: 16933365
hmm i dont get you...how does the varx work? and the date1 and cnt?
0
 
LVL 35

Expert Comment

by:girionis
ID: 16933397
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
0
 

Author Comment

by:basgen
ID: 16933403
okie noted but where does these error msges go?
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 16933410
If you compile the application you will see them in the console.
0
 

Expert Comment

by:Priestex
ID: 16933411
Is this a typing mistake or do you really dont have a closing bracket after the "return today;" statement?
0
 

Author Comment

by:basgen
ID: 16933423
okie, where does the class files go?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 35

Expert Comment

by:girionis
ID: 16933436
I think you should start from the very basic: http://java.sun.com/docs/books/tutorial/getStarted/cupojava/index.html
0
 
LVL 35

Expert Comment

by:girionis
ID: 16933437
> 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.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 16933551
>> System.out.println("End first static init: "                                   ());  

Remove the extra () there.
0
 

Author Comment

by:basgen
ID: 16935052
does not seem to work la...the static is a prob still
0
 
LVL 35

Expert Comment

by:girionis
ID: 16935115
The static is fine, you are probably getting another error. Please post it.
0
 

Author Comment

by:basgen
ID: 16935504
okie..do u have an email address? ill send u the questions..u have a look.think that wld be better
0
 
LVL 35

Expert Comment

by:girionis
ID: 16935524
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
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 16939872
>> }; //end first static initializer block

The semi-colon there is not required.
0
 
LVL 30

Expert Comment

by:mayankeagle
ID: 16941159
What was the problem and what was the solution?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array6 challenfge 6 62
wordcount challenge 11 74
Unable to start eclipse ? 17 83
micro services vs rest web services 16 45
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now