File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes whats wrong with this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "whats wrong with this code" Watch "whats wrong with this code" New topic
Author

whats wrong with this code

ali pak
Greenhorn

Joined: Nov 24, 2001
Posts: 6
// why i am getting NullPointerException
class a
{
public static void main(String[] args)
{
b[] x = new b[5];
x[0].xx = "ali";
System.out.println(x[0].xx);
}
}
class b
{
String xx;
}
Murtuza Thaver
Greenhorn

Joined: Nov 05, 2001
Posts: 3
My guess is u havent initialized the strings in the array correctly.This link might be helpful
http://developer.irt.org/script/4018.htm
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12

// why i am getting NullPointerException

x[0] is null, so you have null.xx which doesn't work.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: whats wrong with this code