Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone tell me whats wrong with this code? I'm new to Java.

Status
Not open for further replies.

Dan2929

Programmer
Aug 11, 2002
6
US
I'm completely new to Java (just started today); i have some experience with C and HTML, but really nothing else. I recently purchased a book called "Learning Java", published by O'Reilly. The first application in the book is of course called "Hello Java", in which a frame is made and the text "Hello Java" is supposed to be printed. However, after typing in the code and trying to compile the program, I get the following error:

----------------------------------------------------------
HelloJava.java [5:1] cannot resolve symbol
symbol : constructor JFrame (java.lang.String)
location: class JFrame
JFrame frame = new JFrame("Hello Java!");
^
1 error
Errors compiling main.

-------------------------------------------------------

Again, since i'm a beginner, I have no idea what I've done wrong, or what this error means. If anybody has a clue as to what I have done wrong in my code, I would appreciate it greatly to know. The code is below, thanks everyone.


---------------------------------------------------
import javax.swing.*;
public class HelloJava
{
public static void main( String[] args ) {
JFrame frame = new JFrame("Hello Java!");
JLabel label = new JLabel("Hello Java!", JLabel.CENTER );
frame.getContentPane().add( label );
frame.setSize( 300, 300 );
frame.setVisible( true );
}
}

-----------------------------------------------------

-Dan
 
By the way, I don't know if it matters, but the compiler I used is something included on the CD that came with the book, its called NetBeans.
 
hi there.... im new to java too (2 days) but i cut and pasted your code saved it as HelloJava.java and ran it in jbuilder 3 and it works.... could it be your package hasnt installed properly...

what location did you install it to (apparently files with spaces in them eg "program files" can cause problems[source:jbuilder documentation])?
or maybe the standard class's arent registered?!?!?!

not much but i hope it gets you started!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top