| | |
connot find symbol symbol class
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 3
Reputation:
Solved Threads: 0
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;
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;
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
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Mar 2007
Posts: 3
Reputation:
Solved Threads: 0
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.
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)
import jpb.*; public class Main { public static void main (String[] args) { Pet MyPet = null; while (true){ //Here we are listing the possible choices. System.out.println("Please choose one of the following options:" + "\n(c) Create a Pet" + "\n(v) View the Current Pet information" + "\n(f) Feed the Pet" + "\n(p) Play with the Pet" + "\n(t) Train the Pet" + "\n(i) Ignore the Pet" + "\n(E) Exit the program"); SimpleIO.prompt("\n --- Your option: "); String option = SimpleIO.readLine(); //Here we want to get the type of animal. if(option.equalsIgnoreCase("c")) { MyPet = new Pet(); SimpleIO.prompt("\nPlease enter Pet's Type:"); String type = SimpleIO.readLine(); int length = type.length(); String letter = type.substring(0, 1); String rest = type.substring(1, length); String TYPE = letter.toUpperCase() + rest.toLowerCase(); MyPet.setType(TYPE); //Here we want to get the name of the animal. SimpleIO.prompt("Please enter Pet's Name:"); String name = SimpleIO.readLine(); length = name.length(); letter = name.substring(0, 1); rest = name.substring(1, length); String NAME = letter.toUpperCase() + rest.toLowerCase(); MyPet.setName(NAME); //Here we want to get the color of the animal. SimpleIO.prompt("Please enter Pet's color:"); String color = SimpleIO.readLine(); length = color.length(); letter = color.substring(0, 1); rest = color.substring(1, length); String COLOR = letter.toUpperCase() + rest.toLowerCase(); MyPet.setColor(COLOR); //Here we want to get the age of the animal. SimpleIO.prompt("Please enter Pet's age:"); String AGE = SimpleIO.readLine(); int age = Integer.parseInt(AGE); MyPet.setAge(age); //Here we want to get the sound the animal makes. SimpleIO.prompt("Please enter Pet's sound:"); String sound = SimpleIO.readLine(); length = sound.length(); letter = sound.substring(0, 1); rest = sound.substring(1, length); String SOUND = letter.toUpperCase() + rest.toLowerCase(); MyPet.setSound(SOUND); //Here we want to get the name of the animal owner. SimpleIO.prompt("Please enter Pet's owner name:"); String owner = SimpleIO.readLine(); length = owner.length(); letter = owner.substring(0, 1); rest = owner.substring(1, length); String OWNER = letter.toUpperCase() + rest.toLowerCase(); MyPet.setOwner(OWNER); //Here we want to output the information on the animal. } else if(option.equalsIgnoreCase("v")) { if(MyPet != null) System.out.print(MyPet); else System.out.print("\nYour pet does not exist"); } //Here we want to feed the animal. else if(option.equalsIgnoreCase("f")) { SimpleIO.prompt("Please enter an amount to feed:"); String amount = SimpleIO.readLine(); MyPet.feed(Integer.parseInt(amount)); } //Here we want to play with the animal. else if(option.equalsIgnoreCase("p")) { MyPet.play(); } //Here we want to train the animal. else if(option.equalsIgnoreCase("t")) { MyPet.train(); } //Here we are ignoring the animal. else if(option.equalsIgnoreCase("i")) { MyPet.ignore(); } //Here we want to exit the program. else{ if(option.equalsIgnoreCase("e")) { System.out.print("\nGood bye!"); break; } else System.out.print("\nInvalid input"); //This last line above is outputed if none of the options were chosen. } } } }
•
•
•
•
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;
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"
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- cannot resolve symbol symbol : variable JoptionPane (IT Professionals' Lounge)
- Cannot find symbol (Java)
- Another "cannot find symbol" compiling error (Java)
- unresolved external symbol when using a hashtable class (C++)
Other Threads in the Java Forum
- Previous Thread: where i m doing wrong.
- Next Thread: Java Class Finder
Views: 2778 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time transfer tree unlimited utility webservices windows






