Solved

NumberFormat Exception in Batch File but not Eclipse

Posted on 2011-03-01
23
745 Views
Last Modified: 2012-05-11


Hello,

I'm not sure how to solve this issue.  The code in Eclipse is running but the batch file throws a number format exception: null

The issue is at the Integer.parseInt.

missingValue = getMissingValueInteger();

 private static int getMissingValueInteger()
    {
        String missingValueProperty = System.getProperty("missingValue");
        int parseIntegerMissingValue = Integer.parseInt(missingValueProperty);
        missingValue = parseIntegerMissingValue;
        return missingValue;
    }

Open in new window

0
Comment
Question by:AndyC1000
  • 8
  • 6
  • 5
  • +3
23 Comments
 
LVL 92

Expert Comment

by:objects
ID: 35014606
looks like the system property is not being set
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35014607

Add
System.out.println("miissinvalue: " + missingValueProperty);
just before
 int parseIntegerMissingValue = Integer.parseInt(missingValueProperty);
       
0
 

Author Comment

by:AndyC1000
ID: 35014654
I debugged the code and it displayed the correct info in Eclipse.

I added an echo in the batch file it returned -DmissingValue=-1 which is the value I passed in using:
SET MISSING_VALUE=-DmissingValue=-1

then:

java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib <package name>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %MISSING_VALUE% %LOGFILE%

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:AndyC1000
ID: 35014655
I meant to write it displayed the correct value.
0
 

Author Comment

by:AndyC1000
ID: 35014753
Could it be a missing library to do with number parsing?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35014776

But you are saying that when you run it

java -DmissingValue="-1"  class_name

it actually works? That seems reasonable looking at the code.
Then what is the issue?
0
 
LVL 92

Expert Comment

by:objects
ID: 35014802
try this:

java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib %MISSING_VALUE% <package name>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME%  %LOGFILE%
0
 

Author Comment

by:AndyC1000
ID: 35014810
The batch file throws a number format exception at:

missingValue = getMissingValueInteger();

 private static int getMissingValueInteger()
    {
        String missingValueProperty = System.getProperty("missingValue");
        int parseIntegerMissingValue = Integer.parseInt(missingValueProperty); <---- here
        missingValue = parseIntegerMissingValue;
        return missingValue;
    }

Open in new window


The strange thing is it works in Eclipse, and I've debugged the method and the correct value is returned.
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35014829
I think its comes with sepace! jsut trim that !!
0
 

Author Comment

by:AndyC1000
ID: 35015108
objects and dravidnsr I used both your suggestions and it worked - there are no errors and the output file is created.

The logging component isn't working when running the batch file.  I've checked the classpath and the jar exists. -classpath bin;lib/log4j-1.2.14.jar;  Any suggestions?

I'm using org.apache.log4j.Logger;

::// Batch File 

@ECHO ON
ECHO STARTED Batch..

if not "%JAVA_HOME%" == "" goto javaHomeAlreadySet
for %%P in (%PATH%) do if exist %%P\java.exe set JAVA_HOME=%%P..\
:javaHomeAlreadySet

:: Directory and file locations
SET INPUT_DIR=data/adaptor/input/State
SET OUTPUT_DIR=data/adaptor/output
SET OUTPUT_FILENAME=output
SET MISSING_VALUE=-DmissingValue=-1 
SET LOGFILE=-DlogFile_var=data\adaptor\logger

:: Date for log file
FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
FOR /F "tokens=5 delims= " %%A in ('echo ^| time ^| find "current" ') DO FOR %%B IN (%%A) DO SET Now=%%B
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
    SET Day=%%A
    SET Month=%%B
    SET Year=%%C
)
FOR /F "tokens=1-3 delims=:.-" %%A IN ("%Now%") DO (
    SET Hour=%%A
    SET Min=%%B
    SET Sec=%%C
)
:: Log file prefix
SET LOGDIR=%Year%-%Month%-%Day%_%Hour%%Min%%Sec%
:: Read and convert output

@ECHO ON

ECHO STARTING 


:: How to run program here-->
java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib %MISSING_VALUE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %LOGFILE%


ECHO FINISHED READING and converting output
::ECHO File %OUTPUTDIR%%OUTPUT_FILENAME%.xml has been created.

pause

:END
ECHO ...End Batch
@ECHO ON

Open in new window





0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35016001
>>
:: How to run program here-->
java  -classpath bin;lib/log4j-1.2.14.jar;lib/commons-collections.jar;commons-lang-2.5.jar;lib/velocity-1.6.4.jar;lib/xercesImpl.jar;lib/castor-0.9.5.2.jar;.\lib %MISSING_VALUE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %LOGFILE%
>>



You're not passing the variables to java properly. You specify them as jvm args but use them as normal program args. You need
java  %MISSING_VALUE% %LOGFILE% -classpath etcetera

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35016076
btw, your batch file also seems to reverse the intended meanings of LOGFILE and LOGDIR
0
 
LVL 10

Expert Comment

by:gordon_vt02
ID: 35017100
Where is your log4j.properties/xml file located, or are you configuring log4j programmatically based on the LOGFILE parameter to your app?  Check your config file too.  If it uses relative paths for the log file, it may be showing up somewhere unexpected based on the working directory when you run the batch file.

Also, if you're using JDK 1.6, you can clean up your classpath a little by using wildcards:

java -classpath bin;lib/* ...

That will load any .jar files in the lib directory into the classpath.
0
 

Author Comment

by:AndyC1000
ID: 35022594
I forgot to add the log4j.properties file.

I've inserted log4j.properties into the lib folder and updated the classpath:

java  -classpath bin;lib\*;lib\log4j.properties;.\lib %MISSING_VALUE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME% %LOGFILE%

Open in new window


Although it still doesn't work.

In my properties file I have:
log4j.appender.rollingFile.File = ${logFile_var}/mylog.log

Notice I set the below in the batch:
SET LOGFILE=-DlogFile_var=data\adaptor\logger

Could this be the problem?  The logging worked in the eclipse project.


0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35022705
In that case

>>log4j.appender.rollingFile.File = ${logFile_var}/mylog.log

should be more like

>>log4j.appender.rollingFile.File = ${LOGFILE}/mylog.log

(but see my comments above about your log paths)
0
 
LVL 92

Expert Comment

by:objects
ID: 35022728
same problem as I fixed for you earier

command line sjhould be:


java  -classpath bin;lib\*;lib\log4j.properties;.\lib %MISSING_VALUE%  %LOGFILE% <package>.<main class> %INPUT_DIR% %OUTPUT_DIR% %OUTPUT_FILENAME%

only put args for your app after the class, args for the vm (like system properties) go before the class
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 35022754
>>same problem as I fixed for you earier

You didn't unfortunately, since LOGFILE was still in the wrong place
0
 

Author Comment

by:AndyC1000
ID: 35023284
Thanks that worked!

The only problem with my batch is specifying the name of the log file.

:: Date for log file
FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
FOR /F "tokens=5 delims= " %%A in ('echo ^| time ^| find "current" ') DO FOR %%B IN (%%A) DO SET Now=%%B
FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
    SET Day=%%A
    SET Month=%%B
    SET Year=%%C
)
FOR /F "tokens=1-3 delims=:.-" %%A IN ("%Now%") DO (
    SET Hour=%%A
    SET Min=%%B
    SET Sec=%%C
)
:: Log file prefix
SET LOG_FILENAME=%Year%-%Month%-%Day%_%Hour%%Min%%Sec%

Then I'm adding to the log4j.properties:
log4j.appender.rollingFile.File = ${LOGDIR}/${LOG_FILENAME}.log

Do I need to insert the argument into eclipse and build/ export again?

Open in new window

0
 

Author Comment

by:AndyC1000
ID: 35023285
Do I need to insert the argument into eclipse and build/ export again?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 35023339
> log4j.appender.rollingFile.File = ${LOGDIR}/${LOG_FILENAME}.log

why did you change the log4j config? What you had before was fine

log4j.appender.rollingFile.File = ${logFile_var}/mylog.log

> Do I need to insert the argument into eclipse and build/ export again?

SHouldn't need to. the only problem was with your batch file
0
 
LVL 92

Expert Comment

by:objects
ID: 35023349
> SET LOG_FILENAME=%Year%-%Month%-%Day%_%Hour%%Min%%Sec%

the rolling file appender will handle naming the file for you.
what you originally had is all you need
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35024947
>>Thanks that worked!

Good - glad i could help. (Posted at http:#35016001 )
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068074
:)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
netstat -ano | find "8000" and taskkill /f /pid 2984 3 84
xampp tool 12 56
hibernate example using maven 12 59
printf performancy 11 73
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

820 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