Question:
Why isn't println("x is " + x) working for me in Java?
Mike D
2010-06-07 11:02:18 UTC
I'm trying to play around with a simple java program but I can't seem to concatenate in my println command. If I just try to output the variable by itself, or the text itself it's fine, but both together causes an error.

Here's my code:
class test{
public static void main(String[] args){
int x = 5;
System.out.println("x is " + x);
}
}

and here's my error:

Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: precision
at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.initializeClass() (/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.5.0.0)
at gnu.gcj.runtime.FirstThread.run() (/usr/lib64/libgcj.so.5.0.0)
at _Jv_ThreadRun(java.lang.Thread) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib64/libgcj.so.5.0.0)
at __gcj_personality_v0 (/dssweb/mike_perl/java/java.version=1.4.2)
at __libc_start_main (/lib64/tls/libc-2.3.4.so)
at _Jv_RegisterClasses (/dssweb/mike_perl/java/java.version=1.4.2)
Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in [file:/usr/share/java/libgcj-3.4.6.jar, file:./, core:/]
at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib64/libgcj.so.5.0.0)
at gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_BytecodeVerifier.verify_instructions_0() (/usr/lib64/libgcj.so.5.0.0)
at _Jv_VerifyMethod(_Jv_InterpMethod) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_PrepareClass(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
at _Jv_WaitForState(java.lang.Class, int) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.VMClassLoader.linkClass0(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib64/libgcj.so.5.0.0)
...8 more
Three answers:
question asker
2010-06-07 13:38:18 UTC
There must be something wrong with the java installation. Try re-installing the Java Development Kit. Also, it looks like you are running an old version of java, so now is a good time to upgrade anyway.
Bob
2010-06-07 11:07:13 UTC
This is how it should look when your compiling from command prompt



javac test.java

java test



Make sure when you type java test there is no .java



It could also be that the JDK was installed the wrong way or it is corrupt... looks like your not running the official version of the JDK either... go to Oracle.com and get the official version and follow the directions provided by them ;) Even though your not running Windows they will have a copy that will work for you.
AnalProgrammer
2010-06-07 12:00:35 UTC
Check out this tutorial link from Sun for the answer.



Have fun.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...