[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Assigning Class To JFrame

Posted on 2011-04-20
11
Medium Priority
?
429 Views
Last Modified: 2012-05-11
Hi,

I am a student studying network management. Within this course we have to do a unit on java. I find programing very difficult. Our coursework is to build a java chess game.

We have been given a Chess Board as an external class that we have to use.

But when I try

new Board().setVisible(true);

I get an error message “cannot find symbol”

This was the way we were tought in the lectures.

I attached the Main.java & Class (Board.java) in question.

I am using Netbeans 6.9

Any help will be much appreciated

Regards
Thomas
 Main.java     Board.java
0
Comment
Question by:Smithers1041
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35433803
Have you created a project in Netbeans?
0
 

Author Comment

by:Smithers1041
ID: 35434181
Yes, called JavaChess contains the two files Main.java & Board.java !
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35434303
Your code compiles fine for me.

Maybe you called the folder JavaChess
but it should be javachess and in the code in lower case ?
Java ias case sensiitive
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:for_yan
ID: 35434319
In netbeeans if you creare project
javachess
it will create folder for package with the same name
The case of the package in the fiolder name and the one you see on top of your code
should be the same. Usually packages in Java are lower case
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35434401
Create a package called 'javachess' off your source root. Move the .java files into there and delete any others
0
 
LVL 92

Expert Comment

by:objects
ID: 35437176
you can either:

1. remove the package statements in both classes, or

2. Move the source into folder of the same name as package

Reda the following for some background

http://download.oracle.com/javase/tutorial/java/package/packages.html
0
 

Author Comment

by:Smithers1041
ID: 35460444
Okay, rebuild project & copied the same code In, and it worked (well sort off) but i get a new problem

"Netbeans Debug Output"

Exception in thread "main" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
        at javachess.Board.PaintPiece(Board.java:137)
        at javachess.Board.RepaintPieces(Board.java:161)
        at javachess.Board.resetPieces(Board.java:130)
        at javachess.Board.newGame(Board.java:59)
        at javachess.Board.InitPieces(Board.java:64)
        at javachess.Board.<init>(Board.java:32)
        at javachess.Main.main(Main.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

Any Idea's ?
0
 
LVL 47

Accepted Solution

by:
for_yan earned 268 total points
ID: 35460786
Well, I have the same thing but that is because I don't have the resource
 boardsquares[i].setIcon(new ImageIcon(getClass().getResource("/game/resources/clear.gif")))

Open in new window


file clear.gif -  I hope, you should have one
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 268 total points
ID: 35460834
In your
 ..\netbeans_projects\javachess\build\classes

 folder you need to create  game/resourses folders and put clear.gif file inside
 respources
0
 
LVL 92

Assisted Solution

by:objects
objects earned 132 total points
ID: 35463622
> Exception in thread "main" java.lang.NullPointerException
>        at javax.swing.ImageIcon.<init>(ImageIcon.java:167)

That error is caused by it not finding your image
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35463644

I actually placed a gif file  into

..\netbeans_projects\javachess\build\classes\game\resources

and named it clear.gif and it worked for me nicely

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question