connot find symbol symbol class

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 3
Reputation: anju114 is an unknown quantity at this point 
Solved Threads: 0
anju114 anju114 is offline Offline
Newbie Poster

connot find symbol symbol class

 
0
  #1
Mar 26th, 2007
Hi
I am having problem compiling a java file Main.java which uses an object of another class, named Pet

I am using Netbeans 5.5 and I don't know where to put the class file Pet.class. I don't have Pet.java
No matter where I keep it the error message I get is

symbol : class Pet
location: class javaapplication8.Main
Pet MyPet = null;
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,264
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: connot find symbol symbol class

 
0
  #2
Mar 26th, 2007
Pet.class is product of Pet.java, that what you get once you compile your source code in java file.
Pet class can't be find because you are not calling that class properly, maybe mistake in spelling or your constractor is not right.
Can you please post your code, I think we will find more errors there
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 3
Reputation: anju114 is an unknown quantity at this point 
Solved Threads: 0
anju114 anju114 is offline Offline
Newbie Poster

Re: connot find symbol symbol class

 
0
  #3
Mar 26th, 2007
My code is as follows.

This is my Main.java
As you can see it is using the Pet object. But it says error in lines

Pet MyPet = null;

and
MyPet = new Pet();

I made a general java application using Netbeans 5.5.

I am much familiar with java but not net beans.

All I know is i have Pet.class which my application is not able to refer. So tell me where should I keep Pet.class so that, I have no compilation error.

  1. import jpb.*;
  2.  
  3. public class Main
  4. {
  5. public static void main (String[] args)
  6. {
  7. Pet MyPet = null;
  8. while (true){
  9. //Here we are listing the possible choices.
  10. System.out.println("Please choose one of the following options:" +
  11. "\n(c) Create a Pet" + "\n(v) View the Current Pet information" +
  12. "\n(f) Feed the Pet" + "\n(p) Play with the Pet" + "\n(t) Train the Pet" +
  13. "\n(i) Ignore the Pet" + "\n(E) Exit the program");
  14. SimpleIO.prompt("\n --- Your option: ");
  15. String option = SimpleIO.readLine();
  16. //Here we want to get the type of animal.
  17. if(option.equalsIgnoreCase("c")) {
  18. MyPet = new Pet();
  19. SimpleIO.prompt("\nPlease enter Pet's Type:");
  20. String type = SimpleIO.readLine();
  21. int length = type.length();
  22. String letter = type.substring(0, 1);
  23. String rest = type.substring(1, length);
  24. String TYPE = letter.toUpperCase() + rest.toLowerCase();
  25. MyPet.setType(TYPE);
  26. //Here we want to get the name of the animal.
  27. SimpleIO.prompt("Please enter Pet's Name:");
  28. String name = SimpleIO.readLine();
  29. length = name.length();
  30. letter = name.substring(0, 1);
  31. rest = name.substring(1, length);
  32. String NAME = letter.toUpperCase() + rest.toLowerCase();
  33. MyPet.setName(NAME);
  34.  
  35. //Here we want to get the color of the animal.
  36. SimpleIO.prompt("Please enter Pet's color:");
  37. String color = SimpleIO.readLine();
  38. length = color.length();
  39. letter = color.substring(0, 1);
  40. rest = color.substring(1, length);
  41. String COLOR = letter.toUpperCase() + rest.toLowerCase();
  42. MyPet.setColor(COLOR);
  43. //Here we want to get the age of the animal.
  44. SimpleIO.prompt("Please enter Pet's age:");
  45. String AGE = SimpleIO.readLine();
  46. int age = Integer.parseInt(AGE);
  47. MyPet.setAge(age);
  48. //Here we want to get the sound the animal makes.
  49. SimpleIO.prompt("Please enter Pet's sound:");
  50. String sound = SimpleIO.readLine();
  51. length = sound.length();
  52. letter = sound.substring(0, 1);
  53. rest = sound.substring(1, length);
  54. String SOUND = letter.toUpperCase() + rest.toLowerCase();
  55. MyPet.setSound(SOUND);
  56. //Here we want to get the name of the animal owner.
  57. SimpleIO.prompt("Please enter Pet's owner name:");
  58. String owner = SimpleIO.readLine();
  59. length = owner.length();
  60. letter = owner.substring(0, 1);
  61. rest = owner.substring(1, length);
  62. String OWNER = letter.toUpperCase() + rest.toLowerCase();
  63. MyPet.setOwner(OWNER);
  64.  
  65. //Here we want to output the information on the animal.
  66. }
  67. else if(option.equalsIgnoreCase("v")) {
  68. if(MyPet != null)
  69. System.out.print(MyPet);
  70. else
  71. System.out.print("\nYour pet does not exist");
  72. }
  73. //Here we want to feed the animal.
  74. else if(option.equalsIgnoreCase("f")) {
  75. SimpleIO.prompt("Please enter an amount to feed:");
  76. String amount = SimpleIO.readLine();
  77. MyPet.feed(Integer.parseInt(amount));
  78. }
  79.  
  80. //Here we want to play with the animal.
  81. else if(option.equalsIgnoreCase("p")) {
  82. MyPet.play();
  83. }
  84. //Here we want to train the animal.
  85. else if(option.equalsIgnoreCase("t")) {
  86. MyPet.train();
  87. }
  88. //Here we are ignoring the animal.
  89. else if(option.equalsIgnoreCase("i")) {
  90. MyPet.ignore();
  91. }
  92. //Here we want to exit the program.
  93. else{
  94. if(option.equalsIgnoreCase("e")) {
  95. System.out.print("\nGood bye!");
  96. break;
  97. }
  98. else
  99. System.out.print("\nInvalid input");
  100. //This last line above is outputed if none of the options were chosen.
  101. }
  102.  
  103. }
  104. }
  105. }








Originally Posted by anju114 View Post
Hi
I am having problem compiling a java file Main.java which uses an object of another class, named Pet

I am using Netbeans 5.5 and I don't know where to put the class file Pet.class. I don't have Pet.java
No matter where I keep it the error message I get is

symbol : class Pet
location: class javaapplication8.Main
Pet MyPet = null;
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,264
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: connot find symbol symbol class

 
0
  #4
Mar 26th, 2007
I do not have "jpb" library so I can't test it fully, but bottom line is you are calling class "Pet" all over place but you are missing this class(looks more like a bean). I asume you downloaded this code from sowhere or you typed from book/website and just didn't check for this class. So you have to get "Pet.java" from sowhere otherwise all the calls for Pet will do nothing and triger compiler for errors

PS: you should rename "Main.java" to something more approperiate like "PetTest.java"
Last edited by peter_budo; Mar 26th, 2007 at 7:59 pm.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 3
Reputation: anju114 is an unknown quantity at this point 
Solved Threads: 0
anju114 anju114 is offline Offline
Newbie Poster

Re: connot find symbol symbol class

 
0
  #5
Mar 26th, 2007
I don't have Pet.java but I have Pet.class will that help.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,264
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: connot find symbol symbol class

 
0
  #6
Mar 26th, 2007
Class is compiled version of java file ready to be used. Problem with this is you can't check if you have all methods there. So where did you get Pet.class then?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: connot find symbol symbol class

 
0
  #7
Mar 28th, 2007
Originally Posted by anju114 View Post
I don't have Pet.java but I have Pet.class will that help.
Yeah, that will solve the problem if it's the correct .class file.
Put this .class file in the directory where you have Main.java and compile again. (idea is to put Pet.class file in a directory that's part of CLASSPATH env var).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2778 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC