While running the below program, I got Null Pointer Exception. Can you please help?
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class daywisetrips
{
public static void main(String[] args) throws IOException,
InterruptedException, ClassNotFoundException
{
Configuration conf = new Configuration();
Job j = new Job(conf, "daywisetrips");
j.setMapperClass(tripmapper.class);
j.setReducerClass(tripreducer.class);
j.setJarByClass(daywisetrips.class);
FileInputFormat.addInputPath(j, new Path(args[0]));
FileOutputFormat.setOutputPath(j, new Path(args[1]));
j.setOutputKeyClass(Text.class);
j.setOutputValueClass(IntWritable.class);
j.waitForCompletion(true);
}
static class tripmapper extends Mapper<LongWritable, Text, Text, IntWritable>
{
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException
{
String weekday[] ={"sun","mon","tue","wed","thu","fri","sat"};
Date date = null;
String line = value.toString();
String []words = line.split("|");
try
{
date = new SimpleDateFormat("M/DD/YYYY").parse(words[1]); //convert
string to date
}
catch(ParseException p)
{
System.out.println("parse exception");
}
String day = weekday[date.getDay()];
context.write(new Text(words[0]+day),new
IntWritable(Integer.parseInt(words[3])));
}
}
static class tripreducer extends Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterable<IntWritable> value, Context
context) throws IOException, InterruptedException
{
int sum = 0;
for(IntWritable i:value)
{
sum = sum+i.get();
}
context.write(key, new IntWritable(sum));
}
}
}