aspose file tools*
The moose likes Beginning Java and the fly likes System.out.println("+i); This statement give runtime error on linux" title="" /> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System.out.println("i -->"+i); This statement give runtime error on linux" Watch "System.out.println("i -->"+i); This statement give runtime error on linux" New topic
Author

System.out.println("i -->"+i); This statement give runtime error on linux

minal silimkar
Ranch Hand

Joined: Nov 25, 2007
Posts: 133
I tried following code on redhat 4, java 6 is installed on my machine.


If I write


Code wroks, but if I write

It gives error as shown above.


Minal Silimkar
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Originally posted by minal silimkar:
Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in [file:/usr/share/java/libgcj-3.4.3.jar, file:./, core:/]

For Java 5.0 and up, the compiler turns string concatenation using + into a StringBuilder call:

is equal to


Now it seems that you are using the JVM that was shippedd with GCJ for executing. That one seems to miss all the Java 5.0 and up features, but more importantly its classes.

Try compiling with -source 1.4 -target 1.4 and see if it works then. This should remove the references to StringBuilder.

Or you could try upgrading your GCJ first and see if the latest version includes StringBuilder.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
minal silimkar
Ranch Hand

Joined: Nov 25, 2007
Posts: 133
Originally posted by Rob Prime

Try compiling with -source 1.4 -target 1.4 and see if it works then. This should remove the references to StringBuilder.
Or you could try upgrading your GCJ first and see if the latest version includes StringBuilder.

I tried compiling same code with -source 1.4 -target 1.4, it works.
I don't have any idea about GCJ, so I didn't tried. Please elaborate GCJ.
Janardan Kelkar
Ranch Hand

Joined: May 05, 2008
Posts: 72

shouldn't the class be public?


When the compiler's not happy, ain't nobody happy.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Originally posted by minal silimkar:
I don't have any idea about GCJ, so I didn't tried. Please elaborate GCJ.

GCJ is part of GCC (Gnu Compiler Collection), and can compile Java source code to native code (mostly Linux only). Unfortunately, it has never had complete support for all classes in the API.

Your stack trace mentioned libgcj so that was why I expected that you were using it.

Originally posted by Janardan Kelkar:
shouldn't the class be public?

No it shouldn't. Default (package level) access is also allowed.
minal silimkar
Ranch Hand

Joined: Nov 25, 2007
Posts: 133
I installed netbeans6.5 and tried

It is working fine.
But on terminal this statement gives error.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

Make sure you are using Sun Java instead of GCJ. You're using GCJ instead of Sun Java 6, despite Java 6 being installed on your machine. How you can make sure that you're using Java 6 instead of GCJ is something that you could best ask on a forum about Red Hat Linux.

What do you get if you give the following command in a terminal?

[ December 30, 2008: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
You would probably use Sun Java instead of GCJ by installing Java in the usual fashion then setting your PATH to have the Sun version appear first.

If you install in /usr/java/jdk1.6... you can add this line to the .bashrc file in your ~ directory

export PATH=/usr/java/jdk1.6.0_11/bin/:$PATH

Obviously you can install Java in a different directory.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: System.out.println("i -->"+i); This statement give runtime error on linux