Attempt to import data from .txt file Returning NullPoint Exception
in
Programming Questions
•
1 year ago
Hi,
Despite the fact that I can see the file in the data folder in my sketch folder everytime I run my sketch I get a nullpoint exception. It doesn't make sense to me because my file structure is correct. I'm using processing on a Mac running Lion, if that helps. Here's my code, it's rough as I'm just getting this project off the ground:
Despite the fact that I can see the file in the data folder in my sketch folder everytime I run my sketch I get a nullpoint exception. It doesn't make sense to me because my file structure is correct. I'm using processing on a Mac running Lion, if that helps. Here's my code, it's rough as I'm just getting this project off the ground:
- // Global Varibales
String[] named = loadStrings("names.txt");
String[] wordOne = { "some ", "people ", "love ", "you "};
String[] wordTwo = {"can ", "you ", "smell ", "cheese "};
String theName = " ";
String theNameFin;
String first = " ";
String firstFin;
String sec = " ";
String secFin;
String fin;
int stepper = 0;
int wordNum = 0;
int cntr = 0; // counter for the if loops in each word choice
void setup()
{
size(700, 200);
smooth();
PFont font = loadFont("Arial-Black-20.vlw");
frameRate(30);
background(0);
}
void draw()
{
background(0);
// Set the Name
if (wordNum == 0)
{
theName = named[stepper];
theNameFin = theName;
cntr++;
if (cntr == 10)
{
theName = theNameFin;
wordNum = 1;
cntr = 0;
}
}
// Set the first word
if (wordNum == 1)
{
first = wordOne[stepper];
firstFin = first;
cntr++;
println(cntr);
if (cntr == 10)
{
first = firstFin;
wordNum = 2;
cntr = 0;
}
}
// set the second word
if (wordNum == 2)
{
sec = wordTwo[stepper];
secFin = sec;
cntr++;
if (cntr == 10)
{
sec = secFin;
wordNum = 3;
cntr = 0;
}
}
println(first + sec);
fin = messageFor.concat(first + sec);
// first.concat(sec); // Concatanate all the strings into one final string
textSize(20);
textAlign(LEFT);
text(fin, 20, 100); //Print the final string to the window
// Re set the stepper to 0 so I don't get a Null pointer exception error in case of -1 return
stepper++;
if (stepper>3)
{
stepper = 0;
}
// This is a means of keeping the loop running for animation testing
if (wordNum == 3)
{
int wee = int(random(0, 30));
println(wee);
if(wee == 3)
{
wordNum =0;
named = " ";
first = " ";
sec = " ";
}
}
}
1