| |

VerySource

 Forgot password?
 Register
Search
View: 825|Reply: 5

Error when calling constructor

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-17 20:20:01
| Show all posts |Read mode
public class Sprite
{
  ...
  public Sprite (Animation anim)
   {
    this.anim = anim;
   }
}

public class Player extends Sprite
{
 ...
 public Player (Animation anim) // Generate a Sprite object instead of a Player object? ? ? ?
    {
     super (anim);
     state = STATE_NORMAL;
    }
}

public class Test
{Animation anima = new Animation ();
  Player player;
  player = new Player (anim); // Error reported, Player (Animation) not defined
}

What is the reason, thank you for your guidance.
Reply

Use magic Report

0

Threads

8

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-1-23 16:09:01
| Show all posts
The landlord, I wrote it wrong, it is anima, not anim!
Animation anima = new Animation ();
player = new Player (anim);
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-24 12:09:02
| Show all posts
Yes. It was the landlord who wrote it wrong. But this typo is very normal! This is the extraordinary benefit!
Reply

Use magic Report

1

Threads

12

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 Invalid IP Address

Post time: 2020-1-25 09:09:01
| Show all posts
No such error can be found ??

Impressed
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-26 09:54:01
| Show all posts
public class Sprite
{
   ...
   public Sprite (Animation anim)
     {
       this.anim = anim;
     }
}
 
public class Player extends Sprite
{
 ...
 public Player (Animation anim) // Generate a Sprite object instead of a Player object? ? ? ?
       {
         super (anim);
         state = STATE_NORMAL;
       }
}
 
public class Test
{Animation anim = new Animation ();
   Player player;
   player = new Player (anim); // Error reported, Player (Animation) is not defined
}
 
Mainly call the Player constructor to generate a Sprite object instead of a Player object? ? ? ?
I don't know what the reason is, can anyone tell me how to modify it?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-18 21:30:01
| Show all posts
The instance variable player of the Test class cannot be defined like this,
Directly use Player player = new Player (anim);.

It is estimated that you need to test the Player class. Without junit, add a main method to the test to run it.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list