# Problems with createGraphics, nullPointer, type mismatch

**URL:** <https://discourse.processing.org/t/problems-with-creategraphics-nullpointer-type-mismatch/20059>\
**Category:** Processing\
**Created:** [April 23, 2020, 10:11am UTC](https://discourse.processing.org/t/problems-with-creategraphics-nullpointer-type-mismatch/20059 "2020-04-23T10:11:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Achimoto](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/achimoto/32/8947_2.png) [@Achimoto](https://discourse.processing.org/u/Achimoto)\
**Post date:** [April 23, 2020, 10:11am UTC](https://discourse.processing.org/t/problems-with-creategraphics-nullpointer-type-mismatch/20059/1 "2020-04-23T10:11:17Z")

</div>

createGraphics on Windows10, mode Java

First problem:  
using FX2D renderer results in a NullPointerException  
at “beginDraw”

Second problem:  
not compiling, Type mismatch, “cannot convert from processing.core.PGraphics to PGraphics”  
(Pure Woodoo. If I copy the code into a new file, problem is gone, but reproduceable with the first file.  
The files are bytewise identical.)

what am I doing wrong?

```auto
// first example:
final String renderer = FX2D; //FX2D; //P2D; //JAVA2D; 
PGraphics pg;

void setup() {
  size(200, 200, renderer);
  pg = createGraphics(100, 100, renderer);
}

void draw() {
  pg.beginDraw(); // --> NullPointerException
  pg.background(102);
  pg.stroke(255);
  pg.line(pg.width*0.5, pg.height*0.5, mouseX, mouseY);
  pg.endDraw();
  image(pg, 50, 50); 
}

```

```auto
// second example:

final String renderer = P2D; //FX2D; //P2D; //JAVA2D; 

// Defaults:
int fps = 30; // Framerate
int displayInitialWidth = 800;
int displayInitialHeight = 600;

// Globals
PGraphics overlay;

/// Screen and rendering settings
void settings()
{
  size(displayInitialWidth, displayInitialHeight, renderer);
  pixelDensity(displayDensity());  
  smooth(4);
}

/// Initialization
void setup() 
{
  frameRate(fps);
  surface.setResizable(true);
  overlay = createGraphics(width, height, renderer);
  overlay.smooth(4);
}

// Loop
void draw()
{
  overlay.beginDraw();
  overlay.background(0xFFFFFFFF);
  overlay.line(0, 0, mouseX, mouseY);
  overlay.endDraw();
  image(overlay, 0, 0);
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [April 23, 2020, 5:40pm UTC](https://discourse.processing.org/t/problems-with-creategraphics-nullpointer-type-mismatch/20059/2 "2020-04-23T17:40:03Z")

</div>

Hi @Achimoto.  
You must use these directly like

> size(200, 200, P2D);

You also are not permitted for instance to use

```auto
width = 100;
height = 100;
size(width, height, P2D)

```

---

<div class="post-metadata">

**Author:** ![Achimoto](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/achimoto/32/8947_2.png) [@Achimoto](https://discourse.processing.org/u/Achimoto)\
**Post date:** [April 23, 2020, 6:37pm UTC](https://discourse.processing.org/t/problems-with-creategraphics-nullpointer-type-mismatch/20059/3 "2020-04-23T18:37:04Z")

</div>

Thank you for the advice,  
(Yes, I should put the variables in settings() ).

But this error stays even if I enter the parameters directly:

Error with FX2D,  
renderer P2D works ok.

```auto
void setup() {
  size(200, 200, FX2D);
  pg = createGraphics(100, 100, FX2D);
}

void draw() {
  pg.beginDraw(); // --> NullPointerException
...

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [April 23, 2020, 10:17pm UTC](https://discourse.processing.org/t/problems-with-creategraphics-nullpointer-type-mismatch/20059/4 "2020-04-23T22:17:58Z")

</div>

> [@Achimoto](#):
>
> But this error stays even if I enter the parameters directly:

Yes with this renderer this is a known issue. See [here.](https://github.com/processing/processing/issues/4638)  
This renderer is still experimental
