Hi,
I read a file that contains words seperated by space into my wordcram program to generate word clouds. I constantly change the data in the file. It works fine for many files. But for some, I get this exception,
Exception in thread "Animation Thread" java.lang.NullPointerException
at wordcram.WordCounter.isStopWord(WordCounter.java:90)
at wordcram.WordCounter.shouldCountWord(WordCounter.java:76)
at wordcram.WordCounter.countWords(WordCounter.java:61)
at wordcram.WordCounter.count(WordCounter.java:54)
at wordcram.WordCram.getWordCramEngine(WordCram.java:726)
at wordcram.WordCram.drawAll(WordCram.java:773)
at election_extractor.WordCloud_Generator.setup(WordCloud_Generator.java:74)
at processing.core.PApplet.handleDraw(PApplet.java:1402)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:662)
and this is my code to generate word clouds,
public class WordCloud_Generator extends PApplet {
private static WordCram wc1;
PImage cachedImage;
public void setup() {
colorMode(255);
stroke(255, 0, 0);
size(600, 600);
background(255);
textAlign(CENTER);
wc1 = new WordCram(this)
.fromTextFile("E:/Obama_Romney.txt")
.withFonter(fonter())
.sizedByWeight(18, 60)
.withAngler(Anglers.horiz())
.withWordPadding(2)
.withPlacer(Placers.centerClump())
.withColorer(Colorers.twoHuesRandomSatsOnWhite(this));
wc1.drawAll();
// Save the image of the wordcram
cachedImage = get();
}
public WordColorer colorer() {
return new WordColorer() {
public int colorFor(Word oneWord) {
return color(0xffB0171F);
}
};
}
public WordFonter fonter() {
return new WordFonter() {
public PFont fontFor(Word word) {
PFont san = createFont("sans", 1);
return san;
}
};
}
static public void main(String args[]) {
Frame f = new JFrame();
f.setLayout(new BorderLayout());
PApplet embed = new WordCloud_Generator();
f.add(embed, BorderLayout.CENTER);
embed.init();
f.pack();
RefineryUtilities.centerFrameOnScreen(f);
f.setVisible(true);
}
}
Pls help.
Thanks
1