gpt4 book ai didi

java - hadoop - java.lang.RuntimeException : java. lang.InstantiationException 异常

转载 作者:可可西里 更新时间:2023-11-01 14:22:33 26 4
gpt4 key购买 nike

我正在尝试从客户端 (widows-7) 运行 map-reduce 程序,这是 map-reduce 类:

Configuration conf =  new Configuration();

conf.addResource(new Path("C:\\app\\hadoop-2.0.0-cdh4.3.0\\etc\\hadoop\\core-site.xml"));
conf.addResource(new Path("C:\\app\\hadoop-2.0.0-cdh4.3.0\\etc\\hadoop\\hdfs-site.xml"));

conf.set("fs.defaultFS", "hdfs://host:8020");
conf.set("mapred.job.tracker", "host:8021");

Job job = new Job(conf, "mapRed");
job.setMapperClass(MapClass.class);
//job.setInputFormatClass(org.apache.hadoop.mapreduce.lib.input.TextInputFormat.class);
int numreducers = 1;

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

Path inp = new Path("/data/test");
FileInputFormat.addInputPath(job, inp);
FileOutputFormat.setOutputPath(job, new Path("/data"));
System.exit(job.waitForCompletion(true) ? 0 : 1);

这个程序抛出异常:

    13/12/14 08:27:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" java.lang.RuntimeException: java.lang.InstantiationException
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:128)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2307)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:87)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2342)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2324)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:351)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:163)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:335)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:194)
at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.addInputPath(FileInputFormat.java:368)
at org.gridedge.finalytics.MRTemplate.main(MRTemplate.java:55)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:126)
... 10 more

我在这里发现了一个类似的问题 InstantiationException in hadoop map reduce program我将 FileInputFormat 更改为 TextInputFormat :

 TextInputFormat.addInputPath(job, inp);
TextOutputFormat.setOutputPath(job, new Path("/data"));

错误保持不变,并在 FileInputFormat.addInputPath(job, inp); 行抛出

最佳答案

正确的配置是在 setInputFormat 方法中设置 TextInputFormat。该行似乎在您的代码中被注释了。请将其注释掉,然后尝试使用

FileInputFormat.addInputPaths。

要设置输入和输出格式,您可以看到以下行。

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

如果您仍然遇到任何错误,请告诉我。

关于java - hadoop - java.lang.RuntimeException : java. lang.InstantiationException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20579302/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com