asugri
asked on
java SimpleDateFormat with gcj (gnu compiler for java)
Hi there,
I would like to use gcj (gnu compiler for java) to protect my java code.
I got problem with java's SimpleDateFormat, however. gcj showed error like
the bottom. The closest info I found from web is in
http://old.nabble.com/SimpleDateFormat-td18000139.html
Any advice is very much appreciated.
Reggie
C:\Program Files\Z33>z33_exe
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r
at java.lang.Class.initialize Class(Unkn own Source)
at java.util.Currency.getInst ance(Unkno wn Source)
at java.text.DecimalFormatSym bols.<init >(Unknown Source)
at java.text.DecimalFormatSym bols.getIn stance(Unk nown Source)
at java.text.NumberFormat.com puteInstan ce(Unknown Source)
at java.text.NumberFormat.get NumberInst ance(Unkno wn Source)
at java.text.SimpleDateFormat .<init>(Un known Source)
at java.text.SimpleDateFormat .<init>(Un known Source)
at z33_exe.getCurrentDate(Unk nown Source)
at z33_exe.read_txt(Unknown Source)
at z33_exe.readLicenseFiles(U nknown Source)
at z33_exe.main(Unknown Source)
Caused by: java.lang.NullPointerExcep tion
at java.io.InputStreamReader. read(Unkno wn Source)
at java.io.BufferedReader.fil l(Unknown Source)
at java.io.BufferedReader.rea dLine(Unkn own Source)
at java.util.Properties.load( Unknown Source)
at java.util.Currency.<clinit >(Unknown Source)
at java.lang.Class.initialize Class(Unkn own Source)
...11 more
I would like to use gcj (gnu compiler for java) to protect my java code.
I got problem with java's SimpleDateFormat, however. gcj showed error like
the bottom. The closest info I found from web is in
http://old.nabble.com/SimpleDateFormat-td18000139.html
Any advice is very much appreciated.
Reggie
C:\Program Files\Z33>z33_exe
Exception in thread "main" java.lang.ExceptionInIniti
at java.lang.Class.initialize
at java.util.Currency.getInst
at java.text.DecimalFormatSym
at java.text.DecimalFormatSym
at java.text.NumberFormat.com
at java.text.NumberFormat.get
at java.text.SimpleDateFormat
at java.text.SimpleDateFormat
at z33_exe.getCurrentDate(Unk
at z33_exe.read_txt(Unknown Source)
at z33_exe.readLicenseFiles(U
at z33_exe.main(Unknown Source)
Caused by: java.lang.NullPointerExcep
at java.io.InputStreamReader.
at java.io.BufferedReader.fil
at java.io.BufferedReader.rea
at java.util.Properties.load(
at java.util.Currency.<clinit
at java.lang.Class.initialize
...11 more
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, I did have some places with BufferedReader.readLine. However, it might not be related because
1. When I hardcoded getCurrentDate to return a date like 09132010, gcj worked OK.
2. When I tried to avoid SimpleDateFormat by using other function (see TestDate.java),
I still get similar error, but I did not have BufferedReader.readLine in the code.
PC@PC_Laptop /cygdrive/c/test_gcj
$ cat TestDate.java
import java.util.*;
import java.text.*;
public class TestDate {
/*
public static final int FULL;
public static final int LONG;
public static final int MEDIUM;
public static final int SHORT;
*/
public static void main (String args[]) {
System.out.println("Test for Date");
Date date1 = new Date();
String DateString = date1.toString();
System.out.println("Date:" + DateString);
Date today = new Date();
DateFormat fmt;
fmt = DateFormat.getDateTimeInst ance(1, 1, Locale.US);
String formatted = fmt.format(today);
System.out.println("today: "+ formatted);
System.out.println();
fmt = DateFormat.getDateTimeInst ance(1, 1, Locale.UK);
formatted = fmt.format(today);
System.out.println("today: "+ formatted);
System.out.println();
fmt = DateFormat.getDateTimeInst ance(0, 1, Locale.UK);
formatted = fmt.format(today);
System.out.println("today: "+ formatted);
System.out.println();
fmt = DateFormat.getDateTimeInst ance(2, 1, Locale.UK);
formatted = fmt.format(today);
System.out.println("today: "+ formatted);
System.out.println();
fmt = DateFormat.getDateTimeInst ance(3, 1, Locale.UK);
formatted = fmt.format(today);
System.out.println("today: "+ formatted);
System.out.println();
}
}
PC@PC_Laptop /cygdrive/c/test_gcj
$ !296
javac TestDate.java
PC@PC_Laptop /cygdrive/c/test_gcj
$ !298
gcj --main=TestDate -o TestDate.exe TestDate.class
PC@PC_Laptop /cygdrive/c/test_gcj
$ ls -l *.exe
-rwxr-xr-x+ 1 PC None 37359 2010-09-13 10:07 TestDate.exe
-rwxr-xr-x+ 1 PC None 30625 2010-09-10 15:35 snippetCalendar.exe
PC@PC_Laptop /cygdrive/c/test_gcj
$ !301
./TestDate
Test for Date
Date:Mon Sep 13 10:08:14 GMT-07:00 2010
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r
at java.lang.Class.initialize Class(Unkn own Source)
at java.util.Currency.getInst ance(Unkno wn Source)
at java.text.DecimalFormatSym bols.<init >(Unknown Source)
at java.text.DecimalFormatSym bols.getIn stance(Unk nown Source)
at java.text.NumberFormat.com puteInstan ce(Unknown Source)
at java.text.NumberFormat.get NumberInst ance(Unkno wn Source)
at java.text.SimpleDateFormat .<init>(Un known Source)
at java.text.DateFormat.compu teInstance (Unknown Source)
at java.text.DateFormat.getDa teTimeInst ance(Unkno wn Source)
at TestDate.main(Unknown Source)
Caused by: java.lang.NullPointerExcep tion
at java.io.InputStreamReader. read(Unkno wn Source)
at java.io.BufferedReader.fil l(Unknown Source)
at java.io.BufferedReader.rea dLine(Unkn own Source)
at java.util.Properties.load( Unknown Source)
at java.util.Currency.<clinit >(Unknown Source)
at java.lang.Class.initialize Class(Unkn own Source)
...9 more
PC@PC_Laptop /cygdrive/c/test_gcj
1. When I hardcoded getCurrentDate to return a date like 09132010, gcj worked OK.
2. When I tried to avoid SimpleDateFormat by using other function (see TestDate.java),
I still get similar error, but I did not have BufferedReader.readLine in the code.
PC@PC_Laptop /cygdrive/c/test_gcj
$ cat TestDate.java
import java.util.*;
import java.text.*;
public class TestDate {
/*
public static final int FULL;
public static final int LONG;
public static final int MEDIUM;
public static final int SHORT;
*/
public static void main (String args[]) {
System.out.println("Test for Date");
Date date1 = new Date();
String DateString = date1.toString();
System.out.println("Date:"
Date today = new Date();
DateFormat fmt;
fmt = DateFormat.getDateTimeInst
String formatted = fmt.format(today);
System.out.println("today:
System.out.println();
fmt = DateFormat.getDateTimeInst
formatted = fmt.format(today);
System.out.println("today:
System.out.println();
fmt = DateFormat.getDateTimeInst
formatted = fmt.format(today);
System.out.println("today:
System.out.println();
fmt = DateFormat.getDateTimeInst
formatted = fmt.format(today);
System.out.println("today:
System.out.println();
fmt = DateFormat.getDateTimeInst
formatted = fmt.format(today);
System.out.println("today:
System.out.println();
}
}
PC@PC_Laptop /cygdrive/c/test_gcj
$ !296
javac TestDate.java
PC@PC_Laptop /cygdrive/c/test_gcj
$ !298
gcj --main=TestDate -o TestDate.exe TestDate.class
PC@PC_Laptop /cygdrive/c/test_gcj
$ ls -l *.exe
-rwxr-xr-x+ 1 PC None 37359 2010-09-13 10:07 TestDate.exe
-rwxr-xr-x+ 1 PC None 30625 2010-09-10 15:35 snippetCalendar.exe
PC@PC_Laptop /cygdrive/c/test_gcj
$ !301
./TestDate
Test for Date
Date:Mon Sep 13 10:08:14 GMT-07:00 2010
Exception in thread "main" java.lang.ExceptionInIniti
at java.lang.Class.initialize
at java.util.Currency.getInst
at java.text.DecimalFormatSym
at java.text.DecimalFormatSym
at java.text.NumberFormat.com
at java.text.NumberFormat.get
at java.text.SimpleDateFormat
at java.text.DateFormat.compu
at java.text.DateFormat.getDa
at TestDate.main(Unknown Source)
Caused by: java.lang.NullPointerExcep
at java.io.InputStreamReader.
at java.io.BufferedReader.fil
at java.io.BufferedReader.rea
at java.util.Properties.load(
at java.util.Currency.<clinit
at java.lang.Class.initialize
...9 more
PC@PC_Laptop /cygdrive/c/test_gcj
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The code did not compile with Locale.getCurrent() and Locales.getCurrent().
Please see error message below.
Thx.
PC@PC_Laptop /cygdrive/c/test_gcj
$ !jav
javac TestDate2.java
TestDate2.java:22: cannot resolve symbol
symbol : variable Locales
location: class TestDate2
fmt = DateFormat.getDateTimeInst ance(1, 1, Locales.getCurrent());
^
1 error
PC@PC_Laptop /cygdrive/c/test_gcj
$ !vi
vi TestDate2.java
PC@PC_Laptop /cygdrive/c/test_gcj
$ !ja
javac TestDate2.java
TestDate2.java:22: cannot resolve symbol
symbol : method getCurrent ()
location: class java.util.Locale
fmt = DateFormat.getDateTimeInst ance(1, 1, Locale.getCurrent());
^
1 error
Please see error message below.
Thx.
PC@PC_Laptop /cygdrive/c/test_gcj
$ !jav
javac TestDate2.java
TestDate2.java:22: cannot resolve symbol
symbol : variable Locales
location: class TestDate2
fmt = DateFormat.getDateTimeInst
^
1 error
PC@PC_Laptop /cygdrive/c/test_gcj
$ !vi
vi TestDate2.java
PC@PC_Laptop /cygdrive/c/test_gcj
$ !ja
javac TestDate2.java
TestDate2.java:22: cannot resolve symbol
symbol : method getCurrent ()
location: class java.util.Locale
fmt = DateFormat.getDateTimeInst
^
1 error
Ohh, sorry, i meant
Locale.getDefault()
Locale.getDefault()
ASKER
Similar (if not identical) error with SimpleDateFormat appearing.
Notiece that I did not use SimpleDateFormat in java code.
Thx.
Reggie
PC@PC_Laptop /cygdrive/c/test_gcj
$ !jav
javac TestDate2.java
PC@PC_Laptop /cygdrive/c/test_gcj
PC@PC_Laptop /cygdrive/c/test_gcj
$ gcj --main=TestDate2 -o TestDate2.exe TestDate2.class
PC@PC_Laptop /cygdrive/c/test_gcj
$ ./TestDate2
Test for Date
Date:Mon Sep 13 12:43:08 GMT-07:00 2010
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r
at java.lang.Class.initialize Class(Unkn own Source)
at java.util.Currency.getInst ance(Unkno wn Source)
at java.text.DecimalFormatSym bols.<init >(Unknown Source)
at java.text.DecimalFormatSym bols.getIn stance(Unk nown Source)
at java.text.NumberFormat.com puteInstan ce(Unknown Source)
at java.text.NumberFormat.get NumberInst ance(Unkno wn Source)
at java.text.SimpleDateFormat .<init>(Un known Source)
at java.text.DateFormat.compu teInstance (Unknown Source)
at java.text.DateFormat.getDa teTimeInst ance(Unkno wn Source)
at TestDate2.main(Unknown Source)
Caused by: java.lang.NullPointerExcep tion
at java.io.InputStreamReader. read(Unkno wn Source)
at java.io.BufferedReader.fil l(Unknown Source)
at java.io.BufferedReader.rea dLine(Unkn own Source)
at java.util.Properties.load( Unknown Source)
at java.util.Currency.<clinit >(Unknown Source)
at java.lang.Class.initialize Class(Unkn own Source)
...9 more
PC@PC_Laptop /cygdrive/c/test_gcj
$ cat TestDate2.java
import java.util.*;
import java.text.*;
public class TestDate2 {
public static void main (String args[]) {
System.out.println("Test for Date");
Date date1 = new Date();
String DateString = date1.toString();
System.out.println("Date:" + DateString);
Date today = new Date();
DateFormat fmt;
fmt = DateFormat.getDateTimeInst ance(1, 1, Locale.getDefault());
Notiece that I did not use SimpleDateFormat in java code.
Thx.
Reggie
PC@PC_Laptop /cygdrive/c/test_gcj
$ !jav
javac TestDate2.java
PC@PC_Laptop /cygdrive/c/test_gcj
PC@PC_Laptop /cygdrive/c/test_gcj
$ gcj --main=TestDate2 -o TestDate2.exe TestDate2.class
PC@PC_Laptop /cygdrive/c/test_gcj
$ ./TestDate2
Test for Date
Date:Mon Sep 13 12:43:08 GMT-07:00 2010
Exception in thread "main" java.lang.ExceptionInIniti
at java.lang.Class.initialize
at java.util.Currency.getInst
at java.text.DecimalFormatSym
at java.text.DecimalFormatSym
at java.text.NumberFormat.com
at java.text.NumberFormat.get
at java.text.SimpleDateFormat
at java.text.DateFormat.compu
at java.text.DateFormat.getDa
at TestDate2.main(Unknown Source)
Caused by: java.lang.NullPointerExcep
at java.io.InputStreamReader.
at java.io.BufferedReader.fil
at java.io.BufferedReader.rea
at java.util.Properties.load(
at java.util.Currency.<clinit
at java.lang.Class.initialize
...9 more
PC@PC_Laptop /cygdrive/c/test_gcj
$ cat TestDate2.java
import java.util.*;
import java.text.*;
public class TestDate2 {
public static void main (String args[]) {
System.out.println("Test for Date");
Date date1 = new Date();
String DateString = date1.toString();
System.out.println("Date:"
Date today = new Date();
DateFormat fmt;
fmt = DateFormat.getDateTimeInst
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
$ ./TestDate2
Test for Date
Date:Mon Sep 13 13:11:59 GMT-07:00 2010
Locale.getDefault() value = C._US
Exception in thread "main" java.lang.ExceptionInIniti alizerErro r
at java.lang.Class.initialize Class(Unkn own Source)
at java.util.Currency.getInst ance(Unkno wn Source)
at java.text.DecimalFormatSym bols.<init >(Unknown Source)
at java.text.DecimalFormatSym bols.getIn stance(Unk nown Source)
at java.text.NumberFormat.com puteInstan ce(Unknown Source)
at java.text.NumberFormat.get NumberInst ance(Unkno wn Source)
at java.text.SimpleDateFormat .<init>(Un known Source)
at java.text.DateFormat.compu teInstance (Unknown Source)
at java.text.DateFormat.getDa teTimeInst ance(Unkno wn Source)
at TestDate2.main(Unknown Source)
Caused by: java.lang.NullPointerExcep tion
at java.io.InputStreamReader. read(Unkno wn Source)
at java.io.BufferedReader.fil l(Unknown Source)
at java.io.BufferedReader.rea dLine(Unkn own Source)
at java.util.Properties.load( Unknown Source)
at java.util.Currency.<clinit >(Unknown Source)
at java.lang.Class.initialize Class(Unkn own Source)
...9 more
Test for Date
Date:Mon Sep 13 13:11:59 GMT-07:00 2010
Locale.getDefault() value = C._US
Exception in thread "main" java.lang.ExceptionInIniti
at java.lang.Class.initialize
at java.util.Currency.getInst
at java.text.DecimalFormatSym
at java.text.DecimalFormatSym
at java.text.NumberFormat.com
at java.text.NumberFormat.get
at java.text.SimpleDateFormat
at java.text.DateFormat.compu
at java.text.DateFormat.getDa
at TestDate2.main(Unknown Source)
Caused by: java.lang.NullPointerExcep
at java.io.InputStreamReader.
at java.io.BufferedReader.fil
at java.io.BufferedReader.rea
at java.util.Properties.load(
at java.util.Currency.<clinit
at java.lang.Class.initialize
...9 more
ASKER
is 4.3.4.
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
public class z33 {
public static void main(String[] args) throws IOException {
.....
String currentDate = getCurrentDate();
.......
}
private static String getCurrentDate() {
Date present_time = new Date();
SimpleDateFormat showTime = new SimpleDateFormat("MMddyyyy
return showTime.format(present_ti
} //function getCurrentDate
}