error sending serial data when serialEvent() is used

I am trying to use Arduino and Processing using a potentiometer to control the sizes of the squares that are drawn on top of this image

Getting the color from its same location, so I can blur the picture with the potentiometer by increasing and reducing the size of the squares.

Unfortunately I keep getting this message:

error, disabling serialEvent() for /dev/tty.usbmodem1421
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at processing.serial.Serial.serialEvent(
at Method)
Caused by: java.lang.NullPointerException
at image_pixels_arduino_controller.serialEvent(
… 8 more

This is the code. Any suggestion will be much appreciated!

import processing.serial.*;
Serial myPort;
PImage myImage;

void setup() {
  size(500, 399);
  // List all the available serial ports
  // I know that the first port in the serial list on my mac
  // is always my  Arduino, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[4], 9600);
  // don't generate a serialEvent() unless you get a newline character:
  myImage = loadImage("rdjr.jpg");
  image(myImage, width/2, height/2);

void draw() {

void serialEvent( Serial myPort) {

  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen:

    for ( int i = 0; i < 1000; i++) {

      float inByte = float(inString); 
      float diagonal = dist(0, 0, width, height);
      inByte = map(inByte, 0, 1023, 0, diagonal);

      int x = int(random(0, width));
      int y = int(random(0, height));

      color getColor = myImage.get(x, y);
      fill(getColor, 50);

      rect(x, y, inByte, inByte);

    // convert to an int and map to the screen:

    for ( int i = 0; i < 1000; i++) {

      float inByte = float(inString);

Most people don’t spell int ‘f’, ‘l’, ‘o’, ‘a’, ‘t’.

Most people don’t feel compelled to do the same thing 1000 times.


What does this print?

  String inString = myPort.readStringUntil('\n');

What did you get?

I am trying to use Arduino and Processing

Where is the Arduino code?