这是我在 mapreduce 中使用并获得空指针异常的代码。我通过配置传递一个变量,将其作为字符串获取并解析并存储在一个 int 数组中并处理它——
int[] results;
public void configure(JobConf job) {
// targetPeriod = Integer.parseInt(job.get("Predict"));
String[] pred = job.get("Predict").split(",");
results = new int[pred.length];
for (int i = 0; i < pred.length; i++) {
try {
results[i] = Integer.parseInt(pred[i]);
} catch (NumberFormatException nfe) {
}
;
}
protected void reduce(final IntWritable key, final Iterable<Text> values,
final Context context) throws IOException, InterruptedException {
// int targetPeriod = Integer.parseInt(predict.trim());
String predictfin = null;
// int targetPeriod = 10;
"EXCEPTION HERE"---->
double[] projectedCumulativeScoreAtTargetPeriod = new double[results.length];
// Participant participant = new Participant(values,targetPeriod);
for (int i = 0; i < results.length; i++) {
Participant participant = new Participant(values, results[i]);
14/07/25 15:23:12 INFO mapred.JobClient: Task Id : attempt_201407110824_0728_r_000000_0, Status : FAILED
java.lang.NullPointerException
at ProjectionReducer.reduce(ProjectionReducer.java:38)
at ProjectionReducer.reduce(ProjectionReducer.java:1)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:177)
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:649)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:418)
at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.Child.main(Child.java:249)