# Crash-Causing Error with trying to display Lives

**URL:** <https://discourse.processing.org/t/crash-causing-error-with-trying-to-display-lives/30706>\
**Category:** Coding Questions\
**Created:** [June 14, 2021, 3:59pm UTC](https://discourse.processing.org/t/crash-causing-error-with-trying-to-display-lives/30706 "2021-06-14T15:59:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spamelim](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@spamelim](https://discourse.processing.org/u/spamelim)\
**Post date:** [June 14, 2021, 3:59pm UTC](https://discourse.processing.org/t/crash-causing-error-with-trying-to-display-lives/30706/1 "2021-06-14T15:59:38Z")

</div>

I have been trying to make a space-shooter type game, and I have been coding lives (which work until I try to display them). My code to display the life count is

```auto
Player p;
void draw()
{
 text("Lives:", 100, 100);
  text(p.getLives(), 100, 145);
}

class Player
int lives
{
Player(float x, float y0{
    lives = PLAYER_LIVES;
 }
public int getLives() {return lives;}
}
// in a separate tab
final static int PLAYER_LIVES = 5;

```

Obviously this is very shortened but this code works without the text line, with the text line, my program crashes and I get an error message:  
Could not run the sketch. (Target VM failed to initialize)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 14, 2021, 4:12pm UTC](https://discourse.processing.org/t/crash-causing-error-with-trying-to-display-lives/30706/2 "2021-06-14T16:12:04Z")

</div>

> [@spamelim](#):
>
> `text(p.getLives(), 100, 145);`

text(str(p.getLives()), 100, 145);

Do you have setup and size()?

---

<div class="post-metadata">

**Author:** ![spamelim](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@spamelim](https://discourse.processing.org/u/spamelim)\
**Post date:** [June 14, 2021, 4:53pm UTC](https://discourse.processing.org/t/crash-causing-error-with-trying-to-display-lives/30706/3 "2021-06-14T16:53:04Z")

</div>

My setup is fullscreen(); and other irrelevant code. Even with a set size, it still happens.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 14, 2021, 7:29pm UTC](https://discourse.processing.org/t/crash-causing-error-with-trying-to-display-lives/30706/4 "2021-06-14T19:29:35Z")

</div>

Your code had many errors, so it didn’t run in the first place. I doubt you ever tried this version

**My version**

this version runs.

```auto

Player p;

// 
final static int PLAYER_LIVES = 5;

void setup() {
  size(665, 664);

  p=new Player(111, 222);
}

void draw() {
  background(0); 
  text("Lives:", 100, 100);
  // text(p.getLives(), 100, 145);
  text(p.getLives(), 100, 145);
}

// ============================================================

class Player {
  int lives;

  Player(float x, float y) {
    lives = PLAYER_LIVES;
  }

  int getLives() {
    return lives;
  }
}
//

```
