Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2007, 02:25 AM
Member
 
Join Date: Jul 2007
Posts: 40
toby is on a distinguished road
Error: no class definition found
Hi, I have a program but I am having a problem getting it to run (it compiled fine).
Its error is that there is no class definition found. I really don't know what that means or how to fix it.
Any one know? and also I'm not sure if I saved it under the right name I saved it under Student.java, is this right?

Code:
class Student { private String firstName; private String lastName; private Address homeAddress; private Address schoolAddress; private int test1; private int test2; private int test3; public Student (String first, String last, Address home, Address school) { lastName=last; firstName=first; homeAddress=home; schoolAddress=school; test1=0; test2=0; test3=0; } public void setTestScore (int testNumber, int testScore) { if (testNumber == 1) test1 = testScore; else if (testNumber == 2) test2 = testScore; else test3 = testScore; } public int getTestScore(int testNumber) { if (testNumber == 1) return test1; else if (testNumber == 2) return test2; else return test3; } public double getAverage() { return (test1 + test2 + test3)/3; } public String toString() { String result = firstName +"\n"+ lastName +"\n"+ "HomeAddress: "+ homeAddress + "\n"+ "schoolAddress: "+ schoolAddress + "\n"+ "test1: " + "test 1" + "\n"+ "test2: " + "test 2" + "\n"+ "test3: " + "test 3" + "\n"+ "average: " +this.getAverage()+"\n"; return result; } } class Course { static int numberStudent = 0; String title; Student student1; Student student2; Student student3; Student student4; Student student5; public Course(String courseTitle) { title=courseTitle; } public void addStudent(String first, String last, Address home, Address school) { switch(numberStudent) { case 0: student1 = new Student(first,last,home,school); case 1: student2 = new Student(first,last,home,school);break; case 2: student3 = new Student(first,last,home,school);break; case 3: student4 = new Student(first,last,home,school);break; case 4: student5 = new Student(first,last,home,school);break; default: System.out.println("No More students allowed in the class"); } numberStudent++; } public String toString() { String results=""; results += student1.toString () +"n"; results += student2.toString () +"n"; results += student3.toString () +"n"; results += student4.toString () +"n"; results += student5.toString () +"n"; return results; } class Address { private String streetAddress; private String city; private String state; private long zipCode; public Address(String stAddress,String cityValue,String stateValue,long zip) { streetAddress = stAddress; city = cityValue; state = stateValue; zipCode = zip; } }
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 11:56 PM
Member
 
Join Date: Jul 2007
Location: Las Vegas
Posts: 14
Sircedric88 is on a distinguished road
Send a message via AIM to Sircedric88
Hey I'm a beginning programmer, but it seems like the test score variables were not initialized as field varialbes, therefore when initialized in one method, they are set only for that method.
(i.e. you never initialized test 1-3 to 0 in your second method, and you never set the value for testNumber.)
That's what I think, you have a bunch of variables (i didn't exactly know where you were goin with this, so if you tell me what you're trying to do, I could perhaps help you out
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-27-2007, 12:17 PM
Senior Member
 
Join Date: Jul 2007
Posts: 130
cruxblack will become famous soon enough
No class definition found means that either ur bin directory haven't been put in the environment variable, u put the wrong input when u run it ex: java student, using lowercase, or missing classpath

Btw, one other possibilities are the access modifier, though, seen from ur code, seems like this isn't supposed to be the main class is it not?

If, just if, this is supposed to be a main class, the error might occur brcause u didn't put a public access for the class, default modifier, like the one ur using, are only usable in subclasses within the directory or outside right?

So, if u wanna run it from the outside, ex: cmd, it'll deny the request

Either u put the class public with a main method, or create another class that uses this class
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-27-2007, 01:16 PM
Member
 
Join Date: Jul 2007
Posts: 10
nitinborge5 is on a distinguished road
Quote:
Originally Posted by toby View Post
Hi, I have a program but I am having a problem getting it to run (it compiled fine).
Its error is that there is no class definition found. I really don't know what that means or how to fix it.
Any one know? and also I'm not sure if I saved it under the right name I saved it under Student.java, is this right?

Code:
class Student { private String firstName; private String lastName; private Address homeAddress; private Address schoolAddress; private int test1; private int test2; private int test3; public Student (String first, String last, Address home, Address school) { lastName=last; firstName=first; homeAddress=home; schoolAddress=school; test1=0; test2=0; test3=0; } public void setTestScore (int testNumber, int testScore) { if (testNumber == 1) test1 = testScore; else if (testNumber == 2) test2 = testScore; else test3 = testScore; } public int getTestScore(int testNumber) { if (testNumber == 1) return test1; else if (testNumber == 2) return test2; else return test3; } public double getAverage() { return (test1 + test2 + test3)/3; } public String toString() { String result = firstName +"\n"+ lastName +"\n"+ "HomeAddress: "+ homeAddress + "\n"+ "schoolAddress: "+ schoolAddress + "\n"+ "test1: " + "test 1" + "\n"+ "test2: " + "test 2" + "\n"+ "test3: " + "test 3" + "\n"+ "average: " +this.getAverage()+"\n"; return result; } } class Course { static int numberStudent = 0; String title; Student student1; Student student2; Student student3; Student student4; Student student5; public Course(String courseTitle) { title=courseTitle; } public void addStudent(String first, String last, Address home, Address school) { switch(numberStudent) { case 0: student1 = new Student(first,last,home,school); case 1: student2 = new Student(first,last,home,school);break; case 2: student3 = new Student(first,last,home,school);break; case 3: student4 = new Student(first,last,home,school);break; case 4: student5 = new Student(first,last,home,school);break; default: System.out.println("No More students allowed in the class"); } numberStudent++; } public String toString() { String results=""; results += student1.toString () +"n"; results += student2.toString () +"n"; results += student3.toString () +"n"; results += student4.toString () +"n"; results += student5.toString () +"n"; return results; } class Address { private String streetAddress; private String city; private String state; private long zipCode; public Address(String stAddress,String cityValue,String stateValue,long zip) { streetAddress = stAddress; city = cityValue; state = stateValue; zipCode = zip; } }
Thanks
hi
do one thing copy this program and again past on new
window and then save it with same name
then it will work
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 07-27-2007, 08:01 PM
Member
 
Join Date: Jul 2007
Location: Las Vegas
Posts: 14
Sircedric88 is on a distinguished road
Send a message via AIM to Sircedric88
haha thanks, I actually learned something
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class not found Exception surendra Java Servlet 4 01-11-2008 07:23 AM
Strange error message "Source not found" ppayal Eclipse 0 11-25-2007 07:19 PM
Eclipse - jumping to method definition Java Tip Java Tips 0 11-07-2007 03:52 PM
Error: javax.servlet.ServletException: Column not found barney JavaServer Pages (JSP) and JSTL 1 08-07-2007 08:20 AM
Error: incompatible types, found: int required: boolean silvia New To Java 1 07-19-2007 08:33 PM


All times are GMT +3. The time now is 03:03 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org