• Post Reply Bookmark Topic Watch Topic
  • New Topic

Stuck in the first java program  RSS feed

 
Darren Ang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i am a newbie in java programming. given suggestion by most user, i download a pdf file of Bruce Eckel's "Thinking in Java 4th Edition", but i stuck in the first program, and i tried to surf net to find solution to solve it, but no luck, i believe it is a small problem, hoping any expert can help me.

first, i am using netbean ide 7.1 with jdk1.7.0_02, according to url http://www.mindviewinc.com/TIJ4/CodeInstructions.html, i install the TIJ4 source code in the directory D:\data\project\java\TIJ4-code. i also change the environment CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;D:\data\project\java\TIJ4-code;. on the other hand, i create a new project named shortform.java, and the source code is listed as below :-

// start
package shortform;
// D:\data\project\java\TIJ4-code
import static net.mindview.util.Print.print;

public class Shortform {
public static void main(String[] args) {
print("This is a test");
}
}
// end

to run the program, i need to add a D:\data\project\java\TIJ4-code folder into shortform->project properties->libraries->Compile section, according to the example in the book, the sample use "import static net.mindview.util.Print.*;" statement, but the netbean compilier show a error on the editor, the error is "Import section does not correspond to the specified code style rules.", so i change to "import static net.mindview.util.Print.print;", then the error is gone.


when i click the "run main project" (F6), the error is show as below :-


// start
Exception in thread "main" java.lang.NoClassDefFoundError: net/mindview/util/Print
at shortform.Shortform.main(Shortform.java:26)
Caused by: java.lang.ClassNotFoundException: net.mindview.util.Print
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 1 more
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)
// end


when i click the "test project (shortform)" (alt-F6), the error is show as below :-


// start -------------------------------------------------
init:
Deleting: D:\data\project\java\test\shortform\build\built-jar.properties
deps-jar:
Updati ng property file: D:\data\project\java\test\shortform\build\built-jar.properties
init:
deps-clean :
Updating property file: D:\data\project\java\test\shortform\build\built-clean.properties
Deleting directory D:\data\project\java\test\shortform\build
clean:
Created dir: D:\data\project\java\test\shortform\build\classes
Created dir: D:\data\project\java\test\shortform\build\empty
Created dir: D:\data\project\java\test\shortform\build\generated-sources\ap-source-output
Compiling 1 source file to D:\data\project\java\test\shortform\build\classes
D:\data\project\java\test\shortform\src\shortform\Shortform.java:8: error: package net.mindview.util does not exist
import static net.mindview.util.Print.print;
D:\data\project\java\test\shortform\src\shortform\Shortform.java:8: error: static import only from classes and interfaces
import static net.mindview.util.Print.print;
D:\data\project\java\test\shortform\src\shortform\Shortform.java:26: error: cannot find symbol
print("This is a test");
symbol: method print(String)
location: class Shortform
3 errors
D:\data\project\java\test\shortform\nbproject\build-impl.xml:605: The following error occurred while executing this line:
D:\data\project\java\test\shortform\nbproject\build-impl.xml:246: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
// end ----------------------------------------------------

please help me if you know the problem, thanks
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file name with a .java extension and the name of the top-level public class that contains the main() method must be the same. In other words, if your top-level public class that contains your main() method is named Shortform, then the file name that contains the source code must be Shortform.java. Java is case-sensitive in all things.
 
Darren Ang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i found the problem. the problem is due to the classpath setting. my PC's CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;D:\data\project\java\TIJ4-code; after i change the classpath to .;D:\data\project\java\TIJ4-code; then the problem solved. i not sure C:\Program Files\Java\jre6\lib\ext\QTJava.zip setting is added from netbean or eclipse, anyway, the problem solved, just like to share with all of you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!