Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to resolve Null Pointer Exception

 
Dtech Pace
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic