Help with arrays and null pointer assignments!!

webmasterbeta

New Member
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 understandwhere 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 rightway. However, when I recall them with my getter, it's as if the get methodehas lost all track of them(the variables), and I get a null pointer assignmenterror. 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 constructorpublic static void setColValue(int colNum, int value){colValue[colNum] = value;maxValue = ( colValue[colNum] >maxValue ? value : maxValue) ;} // end of setterpublic 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..
 
Back
Top