Java – hadoop – java.lang.RuntimeException : java. lang. InstantiationException Exception

hadoop – java.lang.RuntimeException : java. lang. InstantiationException Exception… here is a solution to the problem.

hadoop – java.lang.RuntimeException : java. lang. InstantiationException Exception

I’m trying to run the map-reduce program from the client (widows-7), which is the map-reduce class:

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

This app throws an exception:

    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

I found a similar issue here InstantiationException in hadoop map reduce program I changed FileInputFormat to TextInputFormat :

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

The error remains unchanged and is specified in FileInputFormat.addInputPath(job, inp); Row thrown

Solution

The correct configuration is to set the TextInputFormat in the setInputFormat method. The line seems to be commented in your code. Please comment it out and try it

FileInputFormat.addInputPaths。

To set the input and output format, you can see the following line.

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

Please let me know if you still encounter any errors.

Related Problems and Solutions