Exception in thread "main" java.lang.NullPointerException

时间:2022-10-11 09:18:26

1、在window操作系统上,使用eclipse开发工具从hdfs分布式文件系统上下载文件报空指针异常解决方法:

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(Unknown Source)
at org.apache.hadoop.util.Shell.runCommand(Shell.java:)
at org.apache.hadoop.util.Shell.run(Shell.java:)
at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:)
at org.apache.hadoop.util.Shell.execCommand(Shell.java:)
at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:)
at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:)
at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:)
at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:)
at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:)
at com.bie.hadoop.crud.TextCreateNewFile.copyToLocalFile(TextCreateNewFile.java:)
at com.bie.hadoop.crud.TextCreateNewFile.main(TextCreateNewFile.java:)

2、将hadoop-2.5.0-cdh5.3.6.tar.gz文件在window操作系统解压缩,配置好环境变量。

Exception in thread "main" java.lang.NullPointerException

Exception in thread "main" java.lang.NullPointerException

然后验证一下是否配置成功,操作如window+R,输入cmd:

Exception in thread "main" java.lang.NullPointerException

然后将如下所示的文件hadoop-common-2.2.0-bin-32.rar解压缩,然后全部复制放到hadoop-2.5.0-cdh5.3.6.tar.gz的bin目录下面即可:

Exception in thread "main" java.lang.NullPointerException

最后重启电脑,运行下载程序,解决问题,或者在程序中配置如下所示内容:

System.setProperty("hadoop.home.dir","D:/biexiansheng/hadoop/hadoop-2.5.0-cdh5.3.6");

/***
* 获取到配置信息
* @return
*/
public static Configuration getConfiguration(){
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://192.168.19.131:9000");
//重启机器或者设置这个值
//System.setProperty("hadoop.home.dir","D:/biexiansheng/hadoop/hadoop-2.5.0-cdh5.3.6");
return conf;
}