The problem is as follows:
Class filestruct {int intpara; filestruct () {intpara = 0;} public void setintpara (int I) {intpara = I;} public int getintpara () {return intpara ;}} class read {public void main (string [] ARGs) {filestruct [] FS = new filestruct [10]; for (INT I = 0; I <10; I ++) system. out. println (FS [I]. getintpara );}
In this caseProgramWill throw an exception: Java. Lang. nullpointerexception
There are two errors in the above program: 1. the initialization of the array is not over 2. In the filestruct class, the constructor function is not released to the public.
Cause of error: 1. When initializing non-basic data in Java, new must be used. After using new to create an array, the array is still a reference array. Only after a new object is created and the object is assigned to the array for reference, initialization ends.
2. If the new object is used in the above program to assign values to the array reference, an exception will still be thrown: the constructor filestruct () is not visible
Based on this, the above procedures should be changed:
Class filestruct {int intpara; Public filestruct () {intpara = 0;} public void setintpara (int I) {intpara = I;} public int getintpara () {return intpara ;}} class read {public void main (string [] ARGs) {filestruct [] FS = new filestruct [10]; for (Int J = 0; j <10; j ++) FS [J] = new filestruct (); For (INT I = 0; I <10; I ++) system. out. println (FS [I]. getintpara );}