Getting long error

Hi there, I have an ultrasonic sensor connected to a NRF24L01 measuring distance on the transmitting end, and another NRF24L01 paired with a LCD screen on the receiving end. Im having trouble with the receiving end, reading the distance. Im getting a “Exception in thread “Thread-2146” java.lang.NullPointerException” error. Any guidance?

//* Library: TMRh20/RF24,

// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

void setup() {

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.

  //RF24 STUFF
  radio.openReadingPipe(0, address);

void loop() {

  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:

  //RF24 STUFF
   if (radio.available()) {
    char distance [32] ="";, sizeof(distance));
    char distance [32] ="";, sizeof(distance));
  1. I don't know if the compiler cares but get rid of the extraneous space between "distance" and "[32]"

  2. I don't believe that's a generally accepted way to initialize an array. Perhaps "...= {NULL};" would be more deterministic.

  3. "&distance"; I think you can just use "distance" or &distance[0] but &distance is invalid.


    char distance[32] = {NULL};, sizeof(distance));

I subbed those in and I'm not getting anymore errors, however the LCD isn't showing anything. Not even the lcd.print("Distance"). I ran a lcd hello world example to see if wiring is fine and that seemed to work. Not sure what Im doing wrong now. Thanks for the help tho, now I at least have no more errors!

I suspect weird non-ascii spaces in the source file.

Try replacing all spaces with (say) @, then inspcifing the file to see if there is an yhing in it that looks like a space but isn't. After replacing those, replace all '@' with spaces and your code is repaired.


Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Please READ THIS POST to help you get the best out of the forum.