在进行hdfs的上下载的时候,运行idea出现了空指针异常的问题
package com.ykd;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
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.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import java.io.IOException;
public class UseDemo_1 {
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
//1-声明 Job对象,把mian方法所在的类加载进来
Job job = Job.getInstance(new Configuration(), UseDemo_1.class.getSimpleName());
//2-关联 mapper类 reduce 类
job.setMapperClass(DepMapper.class);
job.setReducerClass(DepReducer.class);
//3-分别 设置 mapper 输出的 key-value数据类型
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
//设置 reduce 输出的 key-value数据类型
job.setMapOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true); //在这里出现问题
}
static class DepMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
IntWritable valu = new IntWritable(1);
Text outKey = new Text();
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String str = new String(value.getBytes(), 0, value.getLength(), "GBK");
String[] arrs = str.trim().split(",");
if (null != arrs && arrs.length > 10 && arrs[10] != null) {
System.out.println("第11个位置上的值是=" + arrs[10]);
if (arrs[10].equals("非营运")) {
outKey.set("乘用车辆");
context.write(outKey, valu);
} else {
outKey.set("商用车辆");
context.write(outKey, valu);
}
}
}
}
static class DepReducer extends Reducer<Text, IntWritable, Text, DoubleWritable> {
IntWritable valu = new IntWritable();
DoubleWritable dw = new DoubleWritable();
double all = 0;
@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable ele : values) {
sum += ele.get();
}
all += sum;
double rs = sum / all;
dw.set(rs);
context.write(key, dw);
}
}
}
报错内容:
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NullPointerException
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1012)
at org.apache.hadoop.util.Shell.runCommand(Shell.java:483)
at org.apache.hadoop.util.Shell.run(Shell.java:456)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:722)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:815)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:798)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:731)
at org.apache.hadoop.fs.RawLocalFileSystem.mkOneDirWithMode(RawLocalFileSystem.java:489)
at org.apache.hadoop.fs.RawLocalFileSystem.mkdirsWithOptionalPermission(RawLocalFileSystem.java:530)
at org.apache.hadoop.fs.RawLocalFileSystem.mkdirs(RawLocalFileSystem.java:507)
at org.apache.hadoop.fs.FilterFileSystem.mkdirs(FilterFileSystem.java:305)
at org.apache.hadoop.mapreduce.JobSubmissionFiles.getStagingDir(JobSubmissionFiles.java:133)
at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:144)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1290)
at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1287)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:1287)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1308)
at com.ykd.CarTypeDemo_5.main(CarTypeDemo_5.java:38)
Process finished with exit code 1
我重新配置过环境,也跟着网上资料尝试过他们的方法,也清理过缓存,还是没有解决这个问题。希望各位可以帮我看一下这个问题。