I need help, I have a class called field and I want to create an array of field objects, but when I execute the code:
Fixed field [] The field; Stable scanner userInput = new scanner (System.in); Static zero createFields () {System.out.print ("Enter the number of required fields:"); Int numFields = userInput.nextInt (); The field = new field [numFields]; Enter a name for (Int i = 0; I
Then I get the following output and error in the console:
Enter the number of required fields: Enter a name for field 1: Test Chart. Exceptions to "main" on java.lang.NullPointerException on TestCart.createFields (TestChart.java44) / Code> Please help people solve I have been trying since no night since no profit.
Therefore, Unless you have an array of fields, none of the field objects have been instantiated. Keep the line
area [i] = new field ();
Before you call
field [i] .setFieldName ();
No comments:
Post a Comment