The moose likes I/O and Streams and the fly likes Unable to resolve Null Pointer Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Unable to resolve Null Pointer Exception " Watch "Unable to resolve Null Pointer Exception " New topic
Author

Unable to resolve Null Pointer Exception

Dtech Pace
Greenhorn

Joined: Nov 19, 2011
Posts: 2
Unable to resolve Null Pointer Exception
Kindly provide solution...

import java.io.*;
public class SearchTxtFiles
{
private static String p="",dp="";
private static String[] paths;
private static String files;
private static int i=0,ti=0,in=0;

public static void main(String[] args) throws IOException
{
SearchTxtFiles vrp=new SearchTxtFiles();
int a=0;
try{ a=vrp.callSystem();} catch(IOException ie){}
System.out.println("total : "+a);
}


final int callSystem()throws IOException
{

File[] roots = File.listRoots();

for(int k=0;k<roots.length;k++)
{
File f= new File(roots[k]+"\\");
File[] lf=f.listFiles();
for(int a=0;a<lf.length;a++)
{
if(lf[a].isFile()||lf[a].isDirectory())
visitAllFiles(lf[a]);
}
}

return ti;
}

public final static void visitAllFiles(File dir)
{
if (dir.isDirectory())
{
if(i>0)
System.out.println(i);
i=0;
String[] children = dir.list();
for (int i=0; i<children.length; i++)
{
visitAllFiles(new File(dir, children[i]));
}
}
else
{
files=dir.getName();
p=dir.getParent();
if(files.endsWith(".txt"));
{
if(i==0)
{
System.out.println(p);
}
i++; ti=ti+i;
}

}
}
}
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

The solution would be to look at the stack trace, which tells you what line of code threw the exception. Then examine that code to see what variables are being dereferenced, and investigate which of them is null and what you can do about that.

Posting the code with no further explanation is not a strategy which will get you anywhere.
 
IntelliJ Java IDE
 
subject: Unable to resolve Null Pointer Exception
 
Threads others viewed
can i use java to check the disk usage?
FileName to write to a .txt File
problem in copying the directory
Couldn't check status of file/directory with casting error
Server Program - Responding To Post Requests From HTML pg.
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture