Null pointer Exception In hadoop Mapreduce Programme

2014-09-16T14:24:10

I have a text file like with tab delimiter

20001204X00000  Accident    10  9   6   Hyd 
20001204X00001  Accident        8   7   vzg 2
20001204X00002  Accident    10  7       sec 1
20001204X00003  Accident    23      9   kkd 23

I want to get the output flight id,total number of passengers, here I have to sum all numerical columns values for total number of passengers Like this

20001204X00000 25
20001204X00001 17
20001204X00002 18
20001204X00003 55

When try to add the four numerical columns I got NullPointer exception, please help how to avoid nullPointerException and how to replace the null or white space values with zero

Actually This is Hadoop Map reduce Java Code

package com.flightsdamage.mr;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class FlightsDamage {
public static class FlightsMaper extends Mapper<LongWritable, Text, Text, LongWritable> {
    LongWritable pass2;
    @Override
    protected void map(LongWritable key, Text value,
            org.apache.hadoop.mapreduce.Mapper.Context context)
            throws IOException, InterruptedException,NumberFormatException,NullPointerException {
        String line = value.toString();
        String[] column=line.split("|");
        Text word=new Text();
        word.set(column[0]);
        String str = "n";
        try {
            long a = Long.parseLong(str);
        long a1=Long.parseLong("col1[]");
        long a2=Long.parseLong("col2[]");
        long a3=Long.parseLong("col3[]");
        long a4=Long.parseLong("col4[]");
        long sum = a1+a2+a3+a4;
        LongWritable pass0 = new LongWritable(a1);
        LongWritable pass = new LongWritable(a2);
        LongWritable pass1 = new LongWritable(a3);
        LongWritable pass3 = new LongWritable(a4);
         pass2 = new LongWritable(sum);

        } catch (Exception e) {
            // TODO: handle exception


        }finally{
            context.write(word,pass2);
        }

        }

        }

public static void main(String[] args)throws Exception {
    Configuration conf = new Configuration();
    Job job = new Job(conf, "Flights MR");
    job.setJarByClass(FlightsDamage.class);
    job.setMapperClass(FlightsMaper.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(LongWritable.class);
    //FileInputFormat.addInputPath(job, new Path("/home/node1/data-AviationData.txt"));
    FileInputFormat.addInputPath(job, new Path("/home/node1/Filghtdamage.txt"));


    FileOutputFormat.setOutputPath(job, new Path("/home/node1/output"));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}

Copyright License:
Author:「mahesh chimmiri」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/25861926/null-pointer-exception-in-hadoop-mapreduce-programme

About “Null pointer Exception In hadoop Mapreduce Programme” questions

I have a text file like with tab delimiter 20001204X00000 Accident 10 9 6 Hyd 20001204X00001 Accident 8 7 vzg 2 20001204X00002 Accident 10 7 sec 1 20001204X00003
I am getting Array index bound of exception in Map programme. Below is the data and mapreduce programme. Data: 1,raja,10,10000 2,jyo,10,10000 3,tej,11,20000 4,tej1,11,20000 MapReduce Programm...
I am a beginner with Hadoop and Java, and I am writing Map, Reduce functions to cluster a set of latitudes and longitudes together into groups based on proximity, and set a magnitude (Number of lat...
I am facing an exception in using Hadoop on local box. Exception in thread "main" java.lang.NoSuchMethodError: org.apache.hadoop.conf.Configuration.addDeprecation(Ljava/lang/String;Ljava/lang/Stri...
I wrote a simple code for read a text file and display the same text as output by using Hadoop Map reduce program,Here i am not using reducer using only mapper to display the input text file I too...
I am facing the NullPointerException with the below code. It would be great if some one can review and help me with the program. The mapper is running fine but, I get an NPE, when I am try to spli...
Hi I am currently writing a map reduce job to run through an hdfs containing images and record output where a file contains red or not. I am currently running into a NullPointerException error and I
I wanted to run a MapReduce-Job on my FreeBSD-Cluster with two nodes but I get the following Exception 14/08/27 14:23:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your
I have been seaching for days now, Please HELP I have a nullpointerexception when executing a simple Wordcount for Hadoop (I have installed a cluster of VMs Ubuntu 14 of hadoop and run eclipse LOC...
I recently came across an issue when using Hadoop FileSystem API and GlobStatus while writing Mapreduce application. Here's snippet of the driver program. FileSystem fs = FileSystem.get(URI.creat...

Copyright License:Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.