easy(?) class problem
in
Programming Questions
•
2 years ago
hi all,
i'am pretty new to processing but have programmed somethings in as3 already. so i'm kind of a semi noob.
but i think my problem should be easy to solve:
i made a class called sucher with two parameters and want to create new instances of it in a for-loop
when i play the sketch i get a NullPointerException - Error.
do you know why?
if i try to instance like
textSucher[0]=new sucher("xyz",1);
->same problem
sucher test = new sucher("xyz",1);
-> works fine. there is maybe somehow a problem with the deklaration of the array?!
here is the (full) code:
i'am pretty new to processing but have programmed somethings in as3 already. so i'm kind of a semi noob.
but i think my problem should be easy to solve:
i made a class called sucher with two parameters and want to create new instances of it in a for-loop
when i play the sketch i get a NullPointerException - Error.
do you know why?
if i try to instance like
textSucher[0]=new sucher("xyz",1);
->same problem
sucher test = new sucher("xyz",1);
-> works fine. there is maybe somehow a problem with the deklaration of the array?!
here is the (full) code:
//Variablen deklarieren
PFont myFont;
String textLaden[];
String textAlles;
String textEinzeln[];
sucher textSucher[];
//String meinTextLaden[] = loadStrings("gedicht.txt");
class sucher {
String wort;
int anzahl;
sucher(String tempWort, int tempAnzahl){
//wort=tempWort;
//anzahl=tempAnzahl;
}
}
//String in einzelne Wörter aufteilen und Satzzeichen etc entfernen
void setup() {
//text einladen
textLaden = loadStrings("Sido1.txt");
//text aus array in normalen string
for(int i=0;i<textLaden.length;i++){
textAlles = textAlles+textLaden[i];
}
//text in die einzelnen wörter splitten und sonderzeichen etc entfernen
textEinzeln = splitTokens(textAlles, " .,!?:");
//println(textEinzeln);
for(int i=0;i<textEinzeln.length;i++){
textSucher[i]= new sucher("test",1);
}
}
1