Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6772313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:32:07+00:00 2026-05-26T15:32:07+00:00

java is giving me the error that Java\Workspace\PROJECTS\Farm\animalLab.java [line: 15] Error: cannot find symbol

  • 0

java is giving me the error that
Java\Workspace\PROJECTS\Farm\animalLab.java [line: 15]
Error: cannot find symbol
symbol: method addAnimal(java.lang.String,int,Farm[])
location: variable farm of type Farm[]

my code is

import java.util.Scanner;

class animalLab{
   public Farm[] farm = new Farm[1000];

public void main(String[]args){
Scanner reader = new Scanner(System.in);
int i = 0;

while(reader.hasNext()){
  if(reader.nextLine() == "Quit")
    break;
  if(reader.nextLine()=="Add"){
    System.out.println("Enter animal to add: ");
    String add = reader.nextLine();
    farm.addAnimal(add, i, farm);
  }

my farm class looks something like this

 class Farm{
public String animal = null;

public Farm(String s){
animal = s;

}

   public String getAnimal(){
return animal;

}

public void addAnimal(String add, int i, Farm farm[]){
for (int x =0; x<farm.length; x++)
  if(farm[x] != null)
  if(farm[x].animal.equals(add)){
  System.out.println(add + " is already in the farm");
  break;
}

farm[i] = new Farm(add);

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:32:07+00:00Added an answer on May 26, 2026 at 3:32 pm

    farm is an array of (many) Farm objects.

    Arrays do not have an addAnimal method. Take time to read the error message closely.

    Look at it like this…

    error: cannot find [the] method addAnimal

    location: variable farm [which is] of type Farm[]

    Consider that farm[x].animal "works" (the expression farm[x] is of type Farm) — how can this be used to fix the compilation error?

    I would recommend naming variables for arrays/collection in a plural form — e.g. farms — to mitigate this sort of confusion. Also, unless there is a requirement to use an array (such as a homework assignment), I would recommend using ArrayList — it makes adding and iterating items easier.

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this error: Exception in thread main java.lang.OutOfMemoryError: Java heap space at
IOException Error in getContentFromUrl method: java.io.FileNotFoundEx We are trying to hit a URL: http://somewebsite.com/somefolder/dosomething?zip=75070&servCat=1
I have imported an Existing Java Application into my Workspace . I see that
Oracle JDBC connection with Weblogic 10 datasource mapping, giving problem java.sql.SQLException: Closed Connection I
Java has a convenient split method: String str = The quick brown fox; String[]
Java Newbie here. I have a JFrame that I added to my netbeans project,
Java SE 6 (64 bit only) is now on OS X and that is
Java is nearing version 7. It occurs to me that there must be plenty
Do you agree that the designers of Java class java.io.IOException should have made it
I have a program that allows a user to type java code into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.