Hadoop Mapreduce : Null Pointer Exception

+1 vote

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));
                }
        }
}

Dec 5, 2019 in Big Data Hadoop by Tarun
• 160 points
247 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Big Data Hadoop

0 votes
1 answer

Hive queries from mapreduce gives Null Pointer Exception.

I think you have upgraded CDH. This ...READ MORE

answered Jun 4, 2019 in Big Data Hadoop by Rihan
216 views
0 votes
1 answer

submitJob method in JobClient of Hadoop throws null pointer

I had this problem as well. But when ...READ MORE

answered Sep 18, 2018 in Big Data Hadoop by Neha
• 6,280 points
108 views
0 votes
1 answer

Hadoop Mapreduce: Class Not Found Exception

Try adding this Job job = new Job(conf, ...READ MORE

answered Oct 29, 2018 in Big Data Hadoop by Omkar
• 69,060 points
1,074 views
0 votes
1 answer

Hadoop mapreduce java: NullPoint Exception

Try this: String cords = it.next().toString(); lattitude = Double.toString((inst.decode(cords))[0]); longitude ...READ MORE

answered Dec 14, 2018 in Big Data Hadoop by Omkar
• 69,060 points
118 views
0 votes
1 answer

Hadoop security GroupMappingServiceProvider exception for Spark job via Dataproc API

One of the reason behin you getting ...READ MORE

answered Mar 22, 2018 in Big Data Hadoop by nitinrawat895
• 10,920 points
198 views
0 votes
1 answer

Hadoop MapReduce vs MongoDB MapReduce

Hadoop vs MongoDB MR: 1) Hadoop's MR can ...READ MORE

answered Mar 26, 2018 in Big Data Hadoop by nitinrawat895
• 10,920 points
316 views
0 votes
1 answer

How hadoop mapreduce job is submitted to worker nodes?

Alright, I think you are basically looking ...READ MORE

answered Mar 29, 2018 in Big Data Hadoop by Ashish
• 2,630 points
2,621 views
0 votes
1 answer

Error running hadoop mapreduce in Python using Hadoop Streaming

Hi As you write mapper and reducer program  ...READ MORE

answered Jan 21 in Big Data Hadoop by anonymous
373 views
0 votes
1 answer