# showMessageDialog() function gives an error

**URL:** https://discourse.processing.org/t/showmessagedialog-function-gives-an-error/34332
**Category:** Beginners
**Created:** [December 28, 2021, 9:26am UTC](https://discourse.processing.org/t/showmessagedialog-function-gives-an-error/34332 "2021-12-28T09:26:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![BernieLomaxxx](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@BernieLomaxxx](https://discourse.processing.org/u/BernieLomaxxx)
#### Post date: [December 28, 2021, 9:26am UTC](https://discourse.processing.org/t/showmessagedialog-function-gives-an-error/34332/1 "2021-12-28T09:26:13Z")

</div>

hello very new to processing, this code is from the book _Processing: An Introduction to Programming_

when I use showMessageDialog after using JOptionPane i get an error saying **"frame cannot be resolved to a variable"**

```auto
import static javax.swing.JOptionPane.*;
String input;
input=showInputDialog("Enter an integer to be squared: ");

int integer;
integer = int(input);

int square;
square = integer*integer;

showMessageDialog(frame,integer+" squared is " + square);

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [December 28, 2021, 2:30pm UTC](https://discourse.processing.org/t/showmessagedialog-function-gives-an-error/34332/2 "2021-12-28T14:30:36Z")

</div>

Hello,

Here is a working example that replaced _frame_ with _null_:

> [@Open console instead of window](https://discourse.processing.org/t/open-console-instead-of-window/31040/8):
>
> Hello, There is always javax.swing.JOptionPane for simple IO: import javax.swing.JOptionPane; int col; void setup() { } void draw() { background(col); } void keyPressed() { thread("MessageDialog\_thread"); } void MessageDialog\_thread() { String strInp = JOptionPane.showInputDialog(null,"Enter a color 0 to 255:"); col = int(strInp); JOptionPane.showMessageDialog(null, col, "Output", JOptionPane.PLAIN\_MESSAGE); }slight_smile

Adding this to your code will also work:

```auto
    import javax.swing.JFrame;
    JFrame frame = new JFrame("JOptionPane showMessageDialog example");

```

Insight gleaned from here:  
_[Java: JOptionPane showMessageDialog examples (part 1) | alvinalexander.com](https://alvinalexander.com/java/joptionpane-showmessagedialog-examples-1/)_

`:)`

---

<div class="post-metadata">

### Author: ![BernieLomaxxx](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@BernieLomaxxx](https://discourse.processing.org/u/BernieLomaxxx)
#### Post date: [December 31, 2021, 8:58pm UTC](https://discourse.processing.org/t/showmessagedialog-function-gives-an-error/34332/3 "2021-12-31T20:58:22Z")

</div>

Thank you glv, hopefully one day I’ll understand WHY that worked, lol, baby steps!

---

<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: [January 2, 2022, 4:12am UTC](https://discourse.processing.org/t/showmessagedialog-function-gives-an-error/34332/4 "2022-01-02T04:12:27Z")

</div>

> [@glv](#):
>
> ```auto
> import javax.swing.JFrame;
> JFrame frame = new JFrame("JOptionPane showMessageDialog example");
> 
> ```

Hopefully you also checked that input != null just in case someone hits the ‘Cancel’ button and a null pointer exception is raised.
