• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
Eclipse IDE Firefox Browser Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shouldn't the class be public?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I installed netbeans6.5 and tried

It is working fine.
But on terminal this statement gives error.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic