This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

This code of mine is not working, Please help.... i am studying from Head first java

 
Mike Kris
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. This works well for me...



2. This works well for me...




3. This works well for me...




4. This is giving me an error.....



I get the following error when i compile the Game class
D:\Java>javac Game.java
Game.java:5: package helpers does not exist
import helpers.GameHelper;
^
Game.java:12: cannot access GameHelper
bad class file: .\GameHelper.class
class file contains wrong class: chap05.GameHelper
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
GameHelper helper = new GameHelper();
^
2 errors



Thanks to all in advance,

Mike

 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D:\Java>javac Game.java
Game.java:5: package helpers does not exist
import helpers.GameHelper;
^
Game.java:12: cannot access GameHelper
bad class file: .\GameHelper.class
class file contains wrong class: chap05.GameHelper
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
GameHelper helper = new GameHelper();
^
2 errors



According to the error which is showing GameHelper is in the package chap05, while importing you imported from helpers.GameHelper
 
Mike Kris
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chap 05......!!!

i am sorry to say, i am very novice and i didn't understand that..... Kindly help me by giving more details or how to fix it please.

Thanks,
Mike
 
Chiranjeevi Kanthraj
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GameHelper.java is in the folder chap05
rename that chap05 folder in D: to helpers
then try to compile
 
Campbell Ritchie
Sheriff
Pie
Posts: 50233
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better to copy the code from the book (though some of it has misprints in), and leave out the package declarations at this stage. They are in the downloaded code to separate the files into folders. You would also miss out most of the "import"s.
 
tarik kaya
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this one is easier than changing folder name i think;


change the code

import helpers.GameHelper;

to

import <yourpackagename>.GameHelper;

it should work
 
Campbell Ritchie
Sheriff
Pie
Posts: 50233
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I still prefer the method of leaving out the package names and import declarations.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic