为什么编译器对getter方法说“找不到符号”?

问题描述

当我尝试编译代码时,每次尝试调用getter方法时,都会一直说“找不到符号”。我很乐意提供有关解决问题的所有建议。

这是主要方法代码


import React,{ useState } from "react";
import classes from "./App.module.scss";

const NewComponent = ({ classNames,content }) => {
  return (
    <div className={classNames} dangerouslySetInnerHTML={{ __html: content }} />
  );
};
export default function App() {
  // const classRef = useRef(null);
  const [multiple,setMultiple] = useState([]);
  const addElement = (e) => {
    const classNames = e.target.dataset.class;
    const content = e.target.dataset.content;
    
    setMultiple([
      ...multiple,// If you dont want to make it multiple times. just remove it
      <NewComponent
        key={Date.Now()}
        classNames={classNames}
        content={content}
      />
    ]);
  };
  return (
    <div className="App">
      <button
        onClick={addElement}
        data-class={classes.tag1}
        data-content={"<p>asdasd</p>"}
      >
        Click here
      </button>
      {multiple}
    </div>
  );
}

}

这是带有定义对象的类的代码

import java.util.Scanner;

public class Assignment10
{
  public static void main(String [] args)
  {
    Scanner in = new Scanner(system.in);
    System.out.println("\nThis program displays some attributes and behaviors of two different dogs.");
    
    //Create two Dogs objects
    Dogs firstDog = new Dogs();
    Dogs secondDog = new Dogs();
    
    //Naming scheme for first dog
    System.out.print("\nWhat would you like to name the first dog? ");
    firstDog.setName(in.nextLine());
    
    //Naming scheme for second dog
    System.out.print("What would you like to name the second dog? ");
    secondDog.setName(in.nextLine());
    
    //Scheme for getting the breed of first dog
    System.out.print("\nWhat is the breed of the first dog? ");
    firstDog.setBreed(in.nextLine());
    
    //Scheme for getting the breed of first dog
    System.out.print("What is the breed of the second dog? ");
    secondDog.setBreed(in.nextLine());
    
    //Scheme to get age of first dog
    System.out.println("\nWhere is the first dog in their lifespan? ");
    System.out.print("Enter 1 for puppy,2 for adolescent,3 for adult,4 for senior: ");
    firstDog.setAge(in.nextInt());

    //Scheme to get age of second dog
    System.out.println("Where is the first dog in their lifespan? ");
    secondDog.setAge(in.nextInt());
    
    //Scheme to get weight of first dog
    System.out.println("\nWhere is the first dog in the weight range?");
    System.out.print("Enter 1 for low,2 for medium,3 for high: ");
    firstDog.setWeight(in.nextInt());
    
    //Scheme to get weight of second dog
    System.out.println("Where is the second dog in the weight range?: ");
    secondDog.setWeight(in.nextInt());
    
    System.out.println("\nThank you for your input.");
    System.out.println("The following describes the first dog:\n");
    
    //displaying the attributes and behaviors of the first dog
    System.out.println( firstDog.getName + " is a " + firstDog.getAge + " month old " + firstDog.getWeight + " pound " + firstDog.getGender + " " + firstDog.getBreed + " who " + firstDog.getFleas + "fleas.");
    
    System.out.print("When their owner tossed over a doggie treat," + firstDog.getName + " jumped in the air and went ");
    firstDog.eating();
    System.out.println();
    
    System.out.print("When " + firstDog.getName + " ran back to their owner after fetching the ball,the " + firstDog.getBreed + " dropped the ball and elatedly went ");
    firstDog.barking();
    System.out.println();
    
    if ( firstDog.getFleas().equals("has") )
    {
        System.out.print("After rolling around in the mud," + firstDog.getName + " always goes ");
        firstDog.scratchingFleas();
    }
    
    //displaying the attributes and behaviors of the second dog
    System.out.println( secondDog.getName + " is a " + secondDog.getAge + " month old " + secondDog.getWeight + " pound " + secondDog.getGender + " " + secondDog.getBreed + " who " + secondDog.getFleas + "fleas.");
    
    System.out.print( secondDog.getName + " loudly goes ");
    secondDog.eating();
    System.out.println(" whenever they eat.");
    
    System.out.print( secondDog.getName + " goes ");
    secondDog.barking();
    System.out.println(" each and every time there's a squirrel in the backyard.");
    
    if ( secondDog.getFleas().equals("has") )
    {
        System.out.print("The owners brought the " + secondDog.getBreed + " to the vet because " + secondDog.getName + " kept going ");
        secondDog.scratchingFleas();
        System.out.print(" as if there were fleas.");
    }
}

我真的很感谢每个帮助您的人!!!

解决方法

您没有打电话给吸气剂。您应该在应该dog.getName做的时候dog.getName();