• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to resolve Null Pointer Exception

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}

}
}
}
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic