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;

Recommended Answers

All 6 Replies

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

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.

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"

I don't have Pet.java but I have Pet.class will that help.

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?

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.