Solved

1 error

Posted on 2006-06-19
18
239 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 
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:Mayank S
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:Mayank S
ID: 16939872
>> }; //end first static initializer block

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

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 58
egit plugin on eclipse 8 82
web application structure 18 100
restrict decimal places for double datatype 10 21
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

861 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