java.lang.runtimeexception:java.lang.nosuchmethodexception:hadoop mapreduce

waxmsbnn  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(423)

我得到java.lang.nosuchmethodexception请帮助我。。。

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
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.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

public class Placeholder extends Configured implements Tool  
{
    private static Path[] filepath;
    private static String filename;
    private static String[] calendartablecolumn;
    private static BufferedReader br;
    private static String placeholder;
    private static String output;
    private static HashMap<String,String> map = new HashMap<String,String>();

    public int run(String[] args) throws Exception {

        String placeholdername = args[3];
        String stratposition = args[4];
        String length = args[5];
        String category = args[6];
        String calendarid = args[7];

        Configuration conf = new Configuration();
        conf.set("placeholdername", placeholdername);
        conf.set("stratposition", stratposition);
        conf.set("length", length);
        conf.set("category", category);
        conf.set("calendarid", calendarid);

        Job job = Job.getInstance(conf, "Placeholder");
        DistributedCache.addCacheFile(new Path(args[2]).toUri(), getConf());

        job.setJarByClass(Placeholder.class);
        job.setMapperClass(PlaceholderMapper.class);
        job.setNumReduceTasks(0);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        return job.waitForCompletion(true) ? 0 : 1;

    }

    public static void main(String[] args) throws Exception {

        int res = ToolRunner.run(new Configuration(), new Placeholder(), args);     
        System.exit(res);
    }

    public class PlaceholderMapper extends Mapper<LongWritable,Text,Text,Text>
    {
        protected void setup(Context context) throws IOException,InterruptedException 
        {
            try {

                filepath = DistributedCache.getLocalCacheFiles(getConf());
                filename = filepath[0].getName().toString();
                br = new BufferedReader(new FileReader(filepath[0].toString()));
                String line = null;
                while ((line = br.readLine()) != null) 
                {
                    calendartablecolumn = line.split("\\,");
                }
            } catch (Exception e) {

            }
        }

        public void map(LongWritable keys, Text value, Context context) throws IOException, InterruptedException 
        {
            String str_placeholdername = context.getConfiguration().get("placeholdername");

            String str_stratposition = context.getConfiguration().get("stratposition");
            int int_stratposition = Integer.parseInt(str_stratposition);

            String str_length = context.getConfiguration().get("length");
            int int_length = Integer.parseInt(str_length);

            String str_category = context.getConfiguration().get("category");

            String str_calendarid = context.getConfiguration().get("calendarid");
            int int_calendarid = Integer.parseInt(str_calendarid);

            if (str_category != null)
            {
                if (str_category.equalsIgnoreCase("filename"))
                {
                    placeholder = filename.substring((int_stratposition-1),(int_length-1));

                }else if (str_category.equalsIgnoreCase("startdate"))
                {
                    map.put(calendartablecolumn[0].trim(),calendartablecolumn[3].trim());
                    placeholder = map.get(int_calendarid);

                }else if (str_category.equalsIgnoreCase("enddate"))
                {
                    map.put(calendartablecolumn[0].trim(),calendartablecolumn[4].trim());
                    placeholder = map.get(int_calendarid);

                }else if (str_category.equalsIgnoreCase("currentdate"))
                {
                    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                    Date date = new Date();
                    String currentdate = (dateFormat.format(date)).toString();
                    placeholder = currentdate.substring((int_stratposition-1),(int_length-1));

                }else if (str_category.equalsIgnoreCase("isdailydata"))
                {

                }

                output = value+","+placeholder;
            }else
            {
                String line =  value.toString();
                output = line.substring((int_stratposition-1),(int_length-1));
            }

            context.write(null,new Text (output));
        }
    }
}

这就是我得到的错误-
错误:java.lang.runtimeexception:java.lang.nosuchmethodexception:com.nielsen.grfe.processor.mapreduce.placeholder$placeholdermapper.()位于org.apache.hadoop.util.reflectionutils.newinstance(reflectionutils)。java:131)在org.apache.hadoop.mapred.maptask.runnewmapper(maptask。java:745)在org.apache.hadoop.mapred.maptask.run(maptask。java:341)在org.apache.hadoop.mapred.yarnchild$2.run(yarnchild。java:163)位于javax.security.auth.subject.doas(subject)的java.security.accesscontroller.doprivileged(本机方法)。java:415)在org.apache.hadoop.security.usergroupinformation.doas(usergroupinformation。java:1671)在org.apache.hadoop.mapred.yarnchild.main(yarnchild。java:158)原因:java.lang.nosuchmethodexception:com.nielsen.grfe.processor.mapreduce.placeholder$placeholdermapper.()位于java.lang.class.getconstructor0(class。java:2849)在java.lang.class.getdeclaredconstructor(class。java:2053)位于org.apache.hadoop.util.reflectionutils.newinstance(reflectionutils。java:125)

gc0ot86w

gc0ot86w1#

我想问题是你的 PlaceholderMapper 班级不是 static ,努力做到 public static .

相关问题