Home arrow static arrow Java Programming [Archive] - Println and identifier expected problem
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Println and identifier expected problem
This topic has 8 replies on 1 page.

Posts:266
Registered: 2/27/04
Println and identifier expected problem  
Jul 12, 2004 7:07 AM



 
I am writing a simple date test program.

For some reason or another my System.out.println is causing compiler errors.
I don't see any syntax problems, maybe it is a conflict with my import statements.

The code follows.

package java.DateTest;

import java.util.*;
import java.util.Date;
import java.text.*;
import java.text.SimpleDateFormat;
import java.sql.*;

public class testDate{

Date theCurrentDate = new Date();

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String strDate = sdf.format(theCurrentDate);

Date theFormattedDate = sdf.parse(strDate);

System.out.println("The compareDate is less than or equal to the dueDate: ");

}

Any ideas?

Thanks.

 

Posts:470
Registered: 6/11/02
Re: Println and identifier expected problem  
Jul 12, 2004 7:19 AM (reply 1 of 8)



 
I think the compiler error result from you trying tot do this while not being inside a method

try this instead (for example, you may want all your variables in your method, depends on what you are doing):
package java.DateTest; import java.util.*;import java.util.Date;import java.text.*;import java.text.SimpleDateFormat;import java.sql.*;  public class testDate{   Date theCurrentDate = new Date();   SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");   public void testDate() {    String strDate = sdf.format(theCurrentDate);     Date theFormattedDate = sdf.parse(strDate);     System.out.println("The compareDate is less than or equal to the dueDate: ");  } }  
 

Posts:73
Registered: 7/13/03
Re: Println and identifier expected problem  
Jul 12, 2004 7:19 AM (reply 2 of 8)



 
import java.util.Date;import java.text.SimpleDateFormat; public class Test { 	public static void main(String[] args) {		Date theCurrentDate = new Date();		System.out.println(theCurrentDate);		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");		System.out.println(sdf.format(theCurrentDate));	}}
 

Posts:266
Registered: 2/27/04
Re: Println and identifier expected problem  
Jul 12, 2004 7:40 AM (reply 3 of 8)



 
Now I get the following error when trying to execute.

java.lang.NoSuchMethodError: main

Any Ideas
 

Posts:73
Registered: 7/13/03
Re: Println and identifier expected problem  
Jul 12, 2004 7:43 AM (reply 4 of 8)



 
http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/compile.html
 

Posts:18,384
Registered: 21.03.00
Re: Println and identifier expected problem  
Jul 12, 2004 7:44 AM (reply 5 of 8)



 
Hi,

You must have a main method in your class. See the reply from merlin

/Kaj
 

Posts:266
Registered: 2/27/04
Re: Println and identifier expected problem  
Jul 12, 2004 7:47 AM (reply 6 of 8)



 
I have a main method in my class.
 

Posts:266
Registered: 2/27/04
Re: Println and identifier expected problem  
Jul 12, 2004 7:48 AM (reply 7 of 8)



 
Here is the code.
It compiles fine but will not execute.

import java.util.*;
import java.util.Date;
import java.text.*;
import java.text.SimpleDateFormat;
import java.sql.*;

public class testDate{

public static void main(String[] args) {

String sql = null;
Date REPORTTRANSDATE = new Date();
String REPORTTABLE = "billercenter";
String REPORTBILLERID = "777";

sql = "SELECT " + REPORTTRANSDATE + " FROM " +
REPORTTABLE + " WHERE " + REPORTBILLERID +
"=?" + " AND " + "TO_DATE(" + REPORTTRANSDATE + ")" +
">=?" + " AND " + "TO_DATE(" + REPORTTRANSDATE + ")" +
"<=?";

System.out.println("SQL is: " + sql);

}
}

 

Posts:18,384
Registered: 21.03.00
Re: Println and identifier expected problem  
Jul 12, 2004 12:02 PM (reply 8 of 8)



 
Hi,

Your class compiles and runs fine. The output is:
SQL is: SELECT Mon Jul 12 21:01:03 CEST 2004 FROM billercenter WHERE 777=? AND TO_DATE(Mon Jul 12 21:01:03 CEST 2004)>=? AND TO_DATE(Mon Jul 12 21:01:03 CEST 2004)<=?

on my system.

How do you try to start the 'application'?
 
This topic has 8 replies on 1 page.