Exception in thread "main" java.lang.NullPointerException

时间:2022-10-11 23:14:54

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:482)
    at org.apache.hadoop.util.Shell.run(Shell.java:455)
    at org.apache.hadoop.util.Shell$ShellCommandExecutor.execute(Shell.java:702)
    at org.apache.hadoop.util.Shell.execCommand(Shell.java:791)
    at org.apache.hadoop.util.Shell.execCommand(Shell.java:774)
    at org.apache.hadoop.fs.RawLocalFileSystem.setPermission(RawLocalFileSystem.java:646)
    at org.apache.hadoop.fs.FilterFileSystem.setPermission(FilterFileSystem.java:472)
    at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:460)
    at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:426)
    at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:906)
    at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:887)
    at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:784)
    at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:365)
    at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:338)
    at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:289)
    at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1968)
    at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1937)
    at org.apache.hadoop.fs.FileSystem.copyToLocalFile(FileSystem.java:1913)
    at com.bie.hadoop.crud.TextCreateNewFile.copyToLocalFile(TextCreateNewFile.java:191)
    at com.bie.hadoop.crud.TextCreateNewFile.main(TextCreateNewFile.java:239)

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