我是apache mahout的新手。我正在尝试使用Apache Mahout的FP增长算法从java运行它。这是我使用的代码,
FPGrowth<String> fp = new FPGrowth<String>();
FileLineIterable file = new FileLineIterable(new File(FPInputFileName));
int minSupport = 2;
int maxHeapSize = 50;
Writer writer = null;
StringOutputConverter output = new StringOutputConverter(new SequenceFileOutputCollector<Text,TopKStringPatterns>(writer));
String pattern = " "; //currently understood as splitter
try{
fp.generateTopKFrequentPatterns(new StringRecordIterator(file,pattern), fp.generateFList(new StringRecordIterator(file, pattern), minSupport), minSupport, maxHeapSize, null, output, null);
}catch(Exception err){
err.printStackTrace();
}
我遇到以下错误:
java.lang.NullPointerException
at org.apache.mahout.fpm.pfpgrowth.fpgrowth.FPGrowth.growth(FPGrowth.java:331)
at org.apache.mahout.fpm.pfpgrowth.fpgrowth.FPGrowth.fpGrowth(FPGrowth.java:211)
at org.apache.mahout.fpm.pfpgrowth.fpgrowth.FPGrowth.generateTopKFrequentPatterns(FPGrowth.java:302)
at org.apache.mahout.fpm.pfpgrowth.fpgrowth.FPGrowth.generateTopKFrequentPatterns(FPGrowth.java:174)
at myProgram.main(myProgram.java:96)
如何解释这个?这是因为writer被设置为null?请帮忙。
此致 psun
答案 0 :(得分:0)
错误是因为我没有正确调用generateTopKFrequentPatterns()方法。一旦我修改了呼叫,就没有错误。