944,050 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3763
  • Java RSS
Mar 26th, 2007
0

connot find symbol symbol class

Expand 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;
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anju114 is offline Offline
3 posts
since Mar 2007
Mar 26th, 2007
0

Re: connot find symbol symbol class

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
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,658 posts
since Dec 2004
Mar 26th, 2007
0

Re: connot find symbol symbol class

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.

Java Syntax (Toggle Plain Text)
  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. }








Click to Expand / Collapse  Quote originally posted by anju114 ...
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;
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anju114 is offline Offline
3 posts
since Mar 2007
Mar 26th, 2007
0

Re: connot find symbol symbol class

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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,658 posts
since Dec 2004
Mar 26th, 2007
0

Re: connot find symbol symbol class

I don't have Pet.java but I have Pet.class will that help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
anju114 is offline Offline
3 posts
since Mar 2007
Mar 26th, 2007
0

Re: connot find symbol symbol class

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?
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,658 posts
since Dec 2004
Mar 28th, 2007
0

Re: connot find symbol symbol class

Click to Expand / Collapse  Quote originally posted by anju114 ...
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).
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: where i m doing wrong.
Next Thread in Java Forum Timeline: Java Class Finder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC