| 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.
|
 |
 |
|
|
subject: Unable to resolve Null Pointer Exception
|
|
|