Exception in thread "main" java.lang.NullPointerException while using org.apache.hadoop DistributedFileSystem

StackOverflow https://stackoverflow.com/questions/22600343

Question

String inputPath = args[0];
FileSystem dfs = new DistributedFileSystem();
FileStatus[] files= null;
try{
     files = dfs.listStatus(new path(inputPath));
}
catch(IOExcpeption err){
    //Do stuff
}

The code build fine with maven. However, when I try to run it, I get a nullPointerException inside the try clause. Any ideas?

Was it helpful?

Solution

Instantiating a FileSystem class requires a Configuration object in the constructor. One very simply way to do this is with the following:

FileSystem lfs = FileSystem.get(new Configuration());

Use this when creating the FileSystem object. This also has the added bonus of using the local configuration, so you don't have to change your code when switching between a hadoop and a local file structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top