|
-
Help with arrays and null pointer assignments!!
Could someone please be kind enough to tell me what I am doing wrong here.
I have been racking my brain for a few days now and I just don't understand
where the problem comes from.
Bassically I have a class that I'm using to keep some static variables in.
The constuctor gets called and the variables are initialized in the right
way. However, when I recall them with my getter, it's as if the get methode
has lost all track of them(the variables), and I get a null pointer assignment
error. Why?
Here Is my storage class:
import javax.swing.JOptionPane;
public class ColumnValues
{
private static final int MAX_COLS = 4; //
private static int colValue[];
private static int maxValue;
public ColumnValues()
{
int colValue[] = new int[MAX_COLS];
colValue[0] = 10;
colValue[1] = 20;
colValue[2] = 30;
colValue[3] = 40;
maxValue = 40;
} // default constructor
public static void setColValue(int colNum, int value)
{
colValue[colNum] = value;
maxValue = ( colValue[colNum] >maxValue ? value : maxValue) ;
} // end of setter
public static int getColValue(int colNum)
{
return colValue[colNum];
}
public static int getMaxValue()
{
return maxValue;
}
} // end of class columnValues;
Here is the driver:
public class BarDriver
{
public static void main(String[] args)
{
ColumnValues cValues = new ColumnValues();
int width, height;
int dummyValue;
dummyValue = ColumnValues.getColValue(1);
JOptionPane.showMessageDialog(null, Integer.toString(dummyValue), "Hi",
JOptionPane.INFORMATION_MESSAGE);
+ ...
}
: The second to the last line gives me null pointer error..
Can some one please help and tell me what I did wrong? Thank you very much..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks