# Why does this code not work?

**URL:** https://discourse.processing.org/t/why-does-this-code-not-work/32696
**Category:** Processing for Android
**Created:** [October 8, 2021, 3:30pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696 "2021-10-08T15:30:08Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 8, 2021, 3:30pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/1 "2021-10-08T15:30:08Z")

</div>

i tried this code in android studio and it says “cannot resolve” next to a lot of lines.

```auto
package com.example.test;

public class Sketch extends PApplet {
    // Sketch.java
package tutorials.androidstudio.fragmentsv4;

import processing.core.PApplet;

    public class Sketch extends PApplet {
        public void settings() {
            size(600, 600);
        }

        public void setup() {
        }

        public void draw() {
            if (mousePressed) {
                ellipse(mouseX, mouseY, 50, 50);
            }
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [October 8, 2021, 3:43pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/2 "2021-10-08T15:43:16Z")

</div>

[Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#runSketch-java.lang.String:A-processing.core.PApplet-](http://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#runSketch-java.lang.String:A-processing.core.PApplet-)

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 9, 2021, 6:49am UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/3 "2021-10-09T06:49:42Z")

</div>

Have you imported processing core into android studio

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 12:41pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/5 "2021-10-09T12:41:49Z")

</div>

i think i did

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/01d9353293230a8c9ad0943bdb7a3bc8a7c45121.png)

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 9, 2021, 1:09pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/6 "2021-10-09T13:09:03Z")

</div>

The guide says it needs to be in the lib folder.

> [@How to add Processing to Android Studio?](https://discourse.processing.org/t/how-to-add-processing-to-android-studio/32642):
>
> how to add processing to android studio?

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 1:12pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/7 "2021-10-09T13:12:10Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/60bd0aeb87d84d8339d668e5bd208f6bd001388f.png)

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 9, 2021, 1:28pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/8 "2021-10-09T13:28:30Z")

</div>

Did you also add it to the dependencies as per the tutorials instructions?

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 1:29pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/9 "2021-10-09T13:29:54Z")

</div>

i think i did. how can I check?

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 9, 2021, 1:39pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/10 "2021-10-09T13:39:47Z")

</div>

Not sure, I’ve only recently created my first empty activity in android studio. I haven’t even added the sketch files.

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 1:40pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/11 "2021-10-09T13:40:48Z")

</div>

well I think i did, I read the steps twice

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 9, 2021, 2:18pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/12 "2021-10-09T14:18:44Z")

</div>

Just tested, it should work, I have no red lines.

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 2:28pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/13 "2021-10-09T14:28:27Z")

</div>

I have no idea what i did wrong, i tried it like three times.

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 2:48pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/14 "2021-10-09T14:48:02Z")

</div>

could you show me what you did?

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 9, 2021, 2:48pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/15 "2021-10-09T14:48:24Z")

</div>

ok so I do have some errors, not all the import statements work

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e5f2c902936145f4143479e205aa882c9a967d77.png)

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 2:50pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/16 "2021-10-09T14:50:27Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7c18b534505d2075be1051bce1905614d567cd0c.png)

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 9, 2021, 8:32pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/17 "2021-10-09T20:32:57Z")

</div>

wait do you have to make the sketch in processing first?

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [October 11, 2021, 9:33am UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/18 "2021-10-11T09:33:50Z")

</div>

could you explain what you did?

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 11, 2021, 1:41pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/19 "2021-10-11T13:41:25Z")

</div>

I followed the steps on the link, however 2 of my imports do not work.

```auto
import androidx.appcompat.app.AppCompatActivity;
import processing.android.CompatUtils;

```

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [October 11, 2021, 2:38pm UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/20 "2021-10-11T14:38:14Z")

</div>

so I figured out I was using the wrong jar. I used the one that i used to build libraries and its slightly different. However now I get an error for `onRequestPermission`

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6a49b33bb46296ef7ba0976d52e3be403e2aafc0.png)

and an error for the fragment activity

```auto
fragment.setView(frame, this);

```

despite both of these error the procject builds fine

 ![Screenshot_20211011_164227_com.example.myapplication](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8030d7287fc539a0bd087d9d487a207c5322c0ed.jpeg)

---

<div class="post-metadata">

### Author: ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)
#### Post date: [October 13, 2021, 2:08am UTC](https://discourse.processing.org/t/why-does-this-code-not-work/32696/21 "2021-10-13T02:08:09Z")

</div>

For whatever it’s worth, I have it running on a Mac also:

 ![AS](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/16a2fc8e7f428a4a52526df74a856ca46b9af853.png)
