IT Community - Software Programming, Web Development and Technical Support

null pointer exception

This is a discussion on null pointer exception within the Java Programming forums, part of the Software Development category; The following code is giving a null pointer exception at line no 11:java.util.Arrays.sort(dir). CODE: import ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 02-12-2009, 11:08 PM
Akhil Akhil is offline
D-Web Trainee
 
Join Date: Feb 2009
Posts: 2
Akhil is on a distinguished road
Post null pointer exception

The following code is giving a null pointer exception at line no 11:java.util.Arrays.sort(dir).
CODE:
import java.io.File;

public class Ls {
public static void main(String args[])
{
String[] dir = new java.io.File("test").list();
java.util.Arrays.sort(dir);
File f[] = new File("test").listFiles();
int len1 = dir.length;
for (int i=0;i<len1; i++)
{
System.out.println(dir[i]);
String name = f[i].getName();
System.out.println(name);
int j=name.indexOf('.');
System.out.println(j);
String newname = name.substring(0,j) + "_BS" + name.substring(j,name.length());
System.out.println(newname);
File newFileName=new File(f[i].getParentFile(), newname);
System.out.println("newFileName="+newFileName);
f[i].renameTo(newFileName);
}
}
}

Can somebody sort it out.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Now new mouse pointer sohel1 C# Programming 1 09-29-2008 05:32 AM
What is the result of comparing NULL with NULL? vijayanand Database Support 1 09-20-2007 07:07 AM
NULL Pointer and a NULL Macro vigneshgets C and C++ Programming 3 09-08-2007 03:24 AM
pointer concept in C vigneshgets C and C++ Programming 1 08-14-2007 01:03 AM
Smart Pointer sundarraja C and C++ Programming 1 07-25-2007 06:06 AM


All times are GMT -7. The time now is 03:32 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0