Solved

java SimpleDateFormat with gcj (gnu compiler for java)

Posted on 2010-09-13
10
550 Views
Last Modified: 2013-11-23
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.ExceptionInInitializerError
   at java.lang.Class.initializeClass(Unknown Source)
   at java.util.Currency.getInstance(Unknown Source)
   at java.text.DecimalFormatSymbols.<init>(Unknown Source)
   at java.text.DecimalFormatSymbols.getInstance(Unknown Source)
   at java.text.NumberFormat.computeInstance(Unknown Source)
   at java.text.NumberFormat.getNumberInstance(Unknown Source)
   at java.text.SimpleDateFormat.<init>(Unknown Source)
   at java.text.SimpleDateFormat.<init>(Unknown Source)
   at z33_exe.getCurrentDate(Unknown Source)
   at z33_exe.read_txt(Unknown Source)
   at z33_exe.readLicenseFiles(Unknown Source)
   at z33_exe.main(Unknown Source)
Caused by: java.lang.NullPointerException
   at java.io.InputStreamReader.read(Unknown Source)
   at java.io.BufferedReader.fill(Unknown Source)
   at java.io.BufferedReader.readLine(Unknown Source)
   at java.util.Properties.load(Unknown Source)
   at java.util.Currency.<clinit>(Unknown Source)
   at java.lang.Class.initializeClass(Unknown Source)
   ...11 more


0
Comment
Question by:asugri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 500 total points
ID: 33664047
could you please post the source as well, as it clearly seems (from Caused by: java.lang.NullPointerException) that you have operated on an initialized variable.
0
 

Author Comment

by:asugri
ID: 33664175
Here is important portion of the ode.  (I use cygwin's gcj.  and gcc/gcj version
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_time);
    } //function getCurrentDate
}
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 500 total points
ID: 33664259
Are you loading any properties file in this class, since i see the following exception stack trace?
<<Caused by: java.lang.NullPointerException
   at java.io.InputStreamReader.read(Unknown Source)
   at java.io.BufferedReader.fill(Unknown Source)
   at java.io.BufferedReader.readLine(Unknown Source)
   at java.util.Properties.load(Unknown Source)>>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:asugri
ID: 33664456
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.getDateTimeInstance(1, 1, Locale.US);
      String formatted = fmt.format(today);
      System.out.println("today:"+ formatted);
      System.out.println();

      fmt = DateFormat.getDateTimeInstance(1, 1, Locale.UK);
      formatted = fmt.format(today);
      System.out.println("today:"+ formatted);
      System.out.println();

      fmt = DateFormat.getDateTimeInstance(0, 1, Locale.UK);
      formatted = fmt.format(today);
      System.out.println("today:"+ formatted);
      System.out.println();

      fmt = DateFormat.getDateTimeInstance(2, 1, Locale.UK);
      formatted = fmt.format(today);
      System.out.println("today:"+ formatted);
      System.out.println();

      fmt = DateFormat.getDateTimeInstance(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.ExceptionInInitializerError
   at java.lang.Class.initializeClass(Unknown Source)
   at java.util.Currency.getInstance(Unknown Source)
   at java.text.DecimalFormatSymbols.<init>(Unknown Source)
   at java.text.DecimalFormatSymbols.getInstance(Unknown Source)
   at java.text.NumberFormat.computeInstance(Unknown Source)
   at java.text.NumberFormat.getNumberInstance(Unknown Source)
   at java.text.SimpleDateFormat.<init>(Unknown Source)
   at java.text.DateFormat.computeInstance(Unknown Source)
   at java.text.DateFormat.getDateTimeInstance(Unknown Source)
   at TestDate.main(Unknown Source)
Caused by: java.lang.NullPointerException
   at java.io.InputStreamReader.read(Unknown Source)
   at java.io.BufferedReader.fill(Unknown Source)
   at java.io.BufferedReader.readLine(Unknown Source)
   at java.util.Properties.load(Unknown Source)
   at java.util.Currency.<clinit>(Unknown Source)
   at java.lang.Class.initializeClass(Unknown Source)
   ...9 more

PC@PC_Laptop /cygdrive/c/test_gcj
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33665253
can you once replace Locale.US with Locales.getCurrent(); and try?
0
 

Author Comment

by:asugri
ID: 33665509
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.getDateTimeInstance(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.getDateTimeInstance(1, 1, Locale.getCurrent());
                                                       ^
1 error
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33665599
Ohh, sorry, i meant
Locale.getDefault()
0
 

Author Comment

by:asugri
ID: 33666057
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.ExceptionInInitializerError
   at java.lang.Class.initializeClass(Unknown Source)
   at java.util.Currency.getInstance(Unknown Source)
   at java.text.DecimalFormatSymbols.<init>(Unknown Source)
   at java.text.DecimalFormatSymbols.getInstance(Unknown Source)
   at java.text.NumberFormat.computeInstance(Unknown Source)
   at java.text.NumberFormat.getNumberInstance(Unknown Source)
   at java.text.SimpleDateFormat.<init>(Unknown Source)
   at java.text.DateFormat.computeInstance(Unknown Source)
   at java.text.DateFormat.getDateTimeInstance(Unknown Source)
   at TestDate2.main(Unknown Source)
Caused by: java.lang.NullPointerException
   at java.io.InputStreamReader.read(Unknown Source)
   at java.io.BufferedReader.fill(Unknown Source)
   at java.io.BufferedReader.readLine(Unknown Source)
   at java.util.Properties.load(Unknown Source)
   at java.util.Currency.<clinit>(Unknown Source)
   at java.lang.Class.initializeClass(Unknown 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.getDateTimeInstance(1, 1, Locale.getDefault());
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 500 total points
ID: 33666105
can you simply print Locale.getDefault()?

System.out.println(Locale.getDefault());

what is the output?
0
 

Author Comment

by:asugri
ID: 33666384
$ ./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.ExceptionInInitializerError
   at java.lang.Class.initializeClass(Unknown Source)
   at java.util.Currency.getInstance(Unknown Source)
   at java.text.DecimalFormatSymbols.<init>(Unknown Source)
   at java.text.DecimalFormatSymbols.getInstance(Unknown Source)
   at java.text.NumberFormat.computeInstance(Unknown Source)
   at java.text.NumberFormat.getNumberInstance(Unknown Source)
   at java.text.SimpleDateFormat.<init>(Unknown Source)
   at java.text.DateFormat.computeInstance(Unknown Source)
   at java.text.DateFormat.getDateTimeInstance(Unknown Source)
   at TestDate2.main(Unknown Source)
Caused by: java.lang.NullPointerException
   at java.io.InputStreamReader.read(Unknown Source)
   at java.io.BufferedReader.fill(Unknown Source)
   at java.io.BufferedReader.readLine(Unknown Source)
   at java.util.Properties.load(Unknown Source)
   at java.util.Currency.<clinit>(Unknown Source)
   at java.lang.Class.initializeClass(Unknown Source)
   ...9 more
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

630 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