Solved

1 error

Posted on 2006-06-19
18
232 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
recursion example 16 111
Java - Why doesn't this JFrame work 3 40
egit plugin on eclipse 8 31
table example 4 20
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

919 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

21 Experts available now in Live!

Get 1:1 Help Now