# Processing no longer displaying image or sound

**URL:** <https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487>\
**Category:** Libraries\
**Created:** [January 30, 2021, 3:54pm UTC](https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487 "2021-01-30T15:54:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TiBasic](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@TiBasic](https://discourse.processing.org/u/TiBasic)\
**Post date:** [January 30, 2021, 3:54pm UTC](https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487/1 "2021-01-30T15:54:00Z")

</div>

Hi, so I’m doing a project with arduino and processing. The arduino code is okay, but my processing code for some reason isn’t working right. It used to display an image as well as run a sound but now it does neither of those things and I have no idea why. The code is as follows. I would be so so grateful if somebody could help me with this.

> import controlP5._;  
> import processing.sound._;  
> SoundFile mySoundFile;  
> ControlP5 cp5;  
> import java.io.File;  
> import processing.opengl._;  
> PImage im;  
> boolean displayImage;  
> boolean var = true;  
> import processing.serial._;  
> Serial myPort; // Create object from Serial class  
> String val; // Data received from the serial port  
> void setup()  
> {  
> String portName = Serial.list()[1];  
> myPort = new Serial(this, portName, 9600);  
> size(500, 500);  
> cp5 = new ControlP5(this);  
> selectInput(“Select a file to process:”, “fileSelected”);  
> cp5.addButton(“onOff”).setValue(0)  
> .setPosition(10,10).setSize(200,19);  
> }  
> void fileSelected(File selection) {  
> println("User selected " + selection.getAbsolutePath());  
> im = loadImage(selection.getAbsolutePath());  
> }  
> public void onOff(int val){  
> displayImage = !displayImage;  
> }  
> void draw()  
> {  
> background(0);  
> if ( myPort.available() \> 0) {  
> String inBuffer = myPort.readStringUntil(10);  
> if (inBuffer != null) {  
> if(inBuffer.indexOf(“h”)!=-1){  
> boolean var = false;  
> println(var);  
> }  
> }  
> if (im != null){  
> if(displayImage){  
> image(im, 0, 30);  
> if (var == false){  
> mySoundFile = new SoundFile(this, “Vocaroo 29 Jan 2021 17\_28\_57 CST 12e5cJxlGN7j.mp3”);  
> mySoundFile.play();  
> }  
> }  
> }  
> }  
> }

Like I said, it worked before and then just decided to stop. My port is ok, and I have the sound file and everything uploaded correctly. The libraries are also installed. I’m really confused at this point. Anything would help.

---

<div class="post-metadata">

**Author:** ![rbrauer](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rbrauer](https://discourse.processing.org/u/rbrauer)\
**Post date:** [January 30, 2021, 11:06pm UTC](https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487/2 "2021-01-30T23:06:28Z")

</div>

In the conditional where you are checking for “h”, you have this:

```auto
boolean var = false;

```

That creates a new variable accessible only in the conditional block. I think you probably want to remove “boolean” so that the value of your global variable of the same name will get changed there.

```auto
var = false;

```

---

<div class="post-metadata">

**Author:** ![TiBasic](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@TiBasic](https://discourse.processing.org/u/TiBasic)\
**Post date:** [January 31, 2021, 5:24am UTC](https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487/3 "2021-01-31T05:24:38Z")

</div>

When I remove the boolean, it says that the var doesn’t exist. Do you know why this is and what I can do to prevent it from happening?

---

<div class="post-metadata">

**Author:** ![rbrauer](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rbrauer](https://discourse.processing.org/u/rbrauer)\
**Post date:** [January 31, 2021, 5:38pm UTC](https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487/4 "2021-01-31T17:38:45Z")

</div>

There are two places in the code posted above that start with “boolean var =”. Only the second one should be changed to just “var =”.

---

<div class="post-metadata">

**Author:** ![TiBasic](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@TiBasic](https://discourse.processing.org/u/TiBasic)\
**Post date:** [January 31, 2021, 10:20pm UTC](https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487/5 "2021-01-31T22:20:12Z")

</div>

I changed the second one but it still didn’t work

---

<div class="post-metadata">

**Author:** ![TiBasic](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@TiBasic](https://discourse.processing.org/u/TiBasic)\
**Post date:** [January 31, 2021, 10:23pm UTC](https://discourse.processing.org/t/processing-no-longer-displaying-image-or-sound/27487/6 "2021-01-31T22:23:23Z")

</div>

It actually won’t even print out if it’s false or true. I’m really confused right now
