| Author |
Array of Objects NullPointer Exception
|
BharathiB balasubramanian
Greenhorn
Joined: May 29, 2004
Posts: 1
|
|
import java.applet.*; import java.awt.*; import java.awt.event.*; class test12 { int x,y; public void show(int xx,int yy) { x=xx; y=yy; System.out.println("TestTest"+x+y); } } public class test1 extends Applet { public void init () { test12 labelbh[]=new test12[4]; labelbh[0].show(); } Null Pointer exception is thrown when I try to access a member function of test12 I am trying to create an array of objects Thanks in Advance Regards Bharathi
|
 |
Jose Botella
Ranch Hand
Joined: Jul 03, 2001
Posts: 2120
|
|
Welcome to the Ranch Bharathi! arrays whose elements are of reference type are initialized to null. Initialize one of the elements of the array with something like labelbh[0] = new test12(); Notice we have a beginner's forum that seems more suitable for this question. This one is devoted to IO and streams.
|
SCJP2. Please Indent your code using UBB Code
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
As per Jose's suggestion, moving to Java in General (Beginner).
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: Array of Objects NullPointer Exception
|
|
|