Hi guys. I can’t understand why I am getting this NullPointerException
error, and the line “text(FileName, width/2, 146);” is highlighted.
Thanks for your help once again.
João
import controlP5.*;
ControlP5 cp5;
DropdownList d1;
DropdownList d2;
PFont font, font1, font2, font3;
import processing.serial.*; //import the Serial library
Serial myPort;
PrintWriter output;
String EepromData[];
String FileName;
String[] NamePath;
String GetFilePath;
byte LoadFileCheck = 0;
int OnlyName;
void setup() {
clear();
size(250, 250); // Create Window
cp5 = new ControlP5(this);
font = createFont("Arial Bold", 18);
font1 = createFont("Arial Bold", 10);
font2 = createFont("Arial Bold", 13);
font3 = createFont("Arial Bold", 12);
// Add Button
cp5.addButton("Open") // "Start" is the name of the Button
.setPosition(140, 165) // x and y coordinates of upper left corner of Button
.setSize(80, 20) // (Width, Height)
.setFont(font1)
.setColorBackground(color(216, 216, 216))
.setColorForeground(color(232, 232, 232))
.setColorActive(color(186, 188, 188))
.setColorLabel(color(0, 0, 0))
;
cp5.addButton("Save") // "Start" is the name of the Button
.setPosition(30, 165) // x and y coordinates of upper left corner of Button
.setSize(80, 20) // (Width, Height)
.setFont(font1)
.setColorBackground(color(216, 216, 216))
.setColorForeground(color(232, 232, 232))
.setColorActive(color(186, 188, 188))
.setColorLabel(color(0, 0, 0))
;
}
void draw() {
background(0, 120, 255); // Background Color (r, g, b) or (0 to 255)
textFont(font);
pushStyle();
if (LoadFileCheck != 1){
textFont(font3);
textAlign(CENTER);
text("No File Selected", width/2, 146);
}
if (LoadFileCheck == 1) {
textFont(font3);
// Start a new style
textAlign(CENTER);
text(FileName, width/2, 146);
}
popStyle();
}
void Save() {
selectOutput("Select a file to write to:", "fileSelected");
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
}
}
void Open() {
selectInput ( "Open iLoopino8 Eeprom:", "fileSelected_in", dataFile( "*.il7" ));
}
void fileSelected_in(File selection) {
textFont(font3);
if (selection == null) {
LoadFileCheck = 0;
} else {
LoadFileCheck = 1;
EepromData = (loadStrings(selection.getAbsolutePath()));
GetFilePath = selection.getAbsolutePath();
NamePath = splitTokens(GetFilePath, System.getProperty("file.separator"));
OnlyName = NamePath.length;
FileName = (NamePath[OnlyName - 1]);
println();
println();
println(FileName);
// text(FileName, 2, 146);
}
}