The test code below leads to a "null pointer deference" bug on a String Array(on line 6). This leads to a NullPointerException.
public class TestString {
public static void main (String args[]) {
String test [] = null;
for (int i =0; i < 5; i++) {
String testName = "sony" + i;
test [k] = testName;
}
}
}
-- How do I fix this?
-- What is it that causes this bug?
Thanks,
Sony
You need to initialize your array like this, before :
test = new String[5];
Whenever you use an array, the JVM need to know it exists and its size.
In java there are many way to initialize arrays.
test = new String[5];
Just create an array with five emplacements. (You can't add a sixth element)
test = new String[]{"1", "2"};
Create an array with two emplacements and which contains the values 1 and 2.
String[] test = {"1", "2"};
Create an array with two emplacements and which contains the values 1 and 2. But as you noticed it must be donne at the same time with array declaration.
In Java arrays are static, you specify a size when you create it, and you can't ever change it.
There are too many errors in your code.
1) What is k?
2) You need to initialize the test array first.
String test[] = new String[5]; // or any other number
You are not initializing your array. On the third row you set it to null and then on the sixth row you're trying to set a string to an array that does not exists. You can initialize the array like this:
String test [] = new String[5];
Change String test[] = null; to String test[] = new String[5];
an array must be initialized.
See: http://download.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
Related
I have a class - xClass, that I want to load into an array of xClass so I the declaration:
xClass mysclass[] = new xClass[10];
myclass[0] = new xClass();
myclass[9] = new xClass();
However, I don't know if I will need 10. I may need 8 or 12 or any other number for that matter. I won't know until runtime.
Can I change the number of elements in an array on the fly?
If so, how?
No you can't change the size of an array once created. You either have to allocate it bigger than you think you'll need or accept the overhead of having to reallocate it needs to grow in size. When it does you'll have to allocate a new one and copy the data from the old to the new:
int[] oldItems = new int[10];
for (int i = 0; i < 10; i++) {
oldItems[i] = i + 10;
}
int[] newItems = new int[20];
System.arraycopy(oldItems, 0, newItems, 0, 10);
oldItems = newItems;
If you find yourself in this situation, I'd highly recommend using the Java Collections instead. In particular ArrayList essentially wraps an array and takes care of the logic for growing the array as required:
List<XClass> myclass = new ArrayList<XClass>();
myclass.add(new XClass());
myclass.add(new XClass());
Generally an ArrayList is a preferable solution to an array anyway for several reasons. For one thing, arrays are mutable. If you have a class that does this:
class Myclass {
private int[] items;
public int[] getItems() {
return items;
}
}
you've created a problem as a caller can change your private data member, which leads to all sorts of defensive copying. Compare this to the List version:
class Myclass {
private List<Integer> items;
public List<Integer> getItems() {
return Collections.unmodifiableList(items);
}
}
In java array length is fixed.
You can use a List to hold the values and invoke the toArray method if needed
See the following sample:
import java.util.List;
import java.util.ArrayList;
import java.util.Random;
public class A {
public static void main( String [] args ) {
// dynamically hold the instances
List<xClass> list = new ArrayList<xClass>();
// fill it with a random number between 0 and 100
int elements = new Random().nextInt(100);
for( int i = 0 ; i < elements ; i++ ) {
list.add( new xClass() );
}
// convert it to array
xClass [] array = list.toArray( new xClass[ list.size() ] );
System.out.println( "size of array = " + array.length );
}
}
class xClass {}
As others have said, you cannot change the size of an existing Java array.
ArrayList is the closest that standard Java has to a dynamic sized array. However, there are some things about ArrayList (actually the List interface) that are not "array like". For example:
You cannot use [ ... ] to index a list. You have to use the get(int) and set(int, E) methods.
An ArrayList is created with zero elements. You cannot simple create an ArrayList with 20 elements and then call set(15, foo).
You cannot directly change the size of an ArrayList. You do it indirectly using the various add, insert and remove methods.
If you want something more array-like, you will need to design your own API. (Maybe someone could chime in with an existing third party library ... I couldn't find one with 2 minutes "research" using Google :-) )
If you only really need an array that grows as you are initializing it, then the solution is something like this.
ArrayList<T> tmp = new ArrayList<T>();
while (...) {
tmp.add(new T(...));
}
// This creates a new array and copies the element of 'tmp' to it.
T[] array = tmp.toArray(new T[tmp.size()]);
You set the number of elements to anything you want at the time you create it:
xClass[] mysclass = new xClass[n];
Then you can initialize the elements in a loop. I am guessing that this is what you need.
If you need to add or remove elements to the array after you create it, then you would have to use an ArrayList.
You can use ArrayList:
import java.util.ArrayList;
import java.util.Iterator;
...
ArrayList<String> arr = new ArrayList<String>();
arr.add("neo");
arr.add("morpheus");
arr.add("trinity");
Iterator<String> foreach = arr.iterator();
while (foreach.hasNext()) System.out.println(foreach.next());
As other users say, you probably need an implementation of java.util.List.
If, for some reason, you finally need an array, you can do two things:
Use a List and then convert it to an array with myList.toArray()
Use an array of certain size. If you need more or less size, you can modify it with java.util.Arrays methods.
Best solution will depend on your problem ;)
Arrays.copyOf() method has many options to fix the problem with Array length increasing dynamically.
Java API
Yes, wrap it and use the Collections framework.
List l = new ArrayList();
l.add(new xClass());
// do stuff
l.add(new xClass());
Then use List.toArray() when necessary, or just iterate over said List.
I recommend using vectors instead. Very easy to use and has many predefined methods for implementation.
import java.util.*;
Vector<Integer> v=new Vector<Integer>(5,2);
to add an element simply use:
v.addElement(int);
In the (5,2) the first 5 is the initial size of the vector. If you exceed the initial size,the vector will grow by 2 places. If it exceeds again, then it will again increase by 2 places and so on.
Where you declare the myclass[] array as :
xClass myclass[] = new xClass[10]
, simply pass in as an argument the number of XClass elements you'll need. At that point do you know how many you will need? By declaring the array as having 10 elements, you are not declaring 10 XClass objects, you're simply creating an array with 10 elements of type xClass.
Java Array sizes are fixed , You cannot make dynamic Arrays as that of in C++.
Yes, we can do this way.
import java.util.Scanner;
public class Collection_Basic {
private static Scanner sc;
public static void main(String[] args) {
Object[] obj=new Object[4];
sc = new Scanner(System.in);
//Storing element
System.out.println("enter your element");
for(int i=0;i<4;i++){
obj[i]=sc.nextInt();
}
/*
* here, size reaches with its maximum capacity so u can not store more element,
*
* for storing more element we have to create new array Object with required size
*/
Object[] tempObj=new Object[10];
//copying old array to new Array
int oldArraySize=obj.length;
int i=0;
for(;i<oldArraySize;i++){
tempObj[i]=obj[i];
}
/*
* storing new element to the end of new Array objebt
*/
tempObj[i]=90;
//assigning new array Object refeence to the old one
obj=tempObj;
for(int j=0;j<obj.length;j++){
System.out.println("obj["+j+"] -"+obj[j]);
}
}
}
Since ArrayList takes to much memory when I need array of primitive types, I prefer using IntStream.builder() for creating int array (You can also use LongStream and DoubleStream builders).
Example:
Builder builder = IntStream.builder();
int arraySize = new Random().nextInt();
for(int i = 0; i<arraySize; i++ ) {
builder.add(i);
}
int[] array = builder.build().toArray();
Note: available since Java 8.
It is a good practice get the amount you need to store first then initialize the array.
for example, you would ask the user how many data he need to store and then initialize it, or query the component or argument of how many you need to store.
if you want a dynamic array you could use ArrayList() and use al.add(); function to keep adding, then you can transfer it to a fixed array.
//Initialize ArrayList and cast string so ArrayList accepts strings (or anything
ArrayList<string> al = new ArrayList();
//add a certain amount of data
for(int i=0;i<x;i++)
{
al.add("data "+i);
}
//get size of data inside
int size = al.size();
//initialize String array with the size you have
String strArray[] = new String[size];
//insert data from ArrayList to String array
for(int i=0;i<size;i++)
{
strArray[i] = al.get(i);
}
doing so is redundant but just to show you the idea, ArrayList can hold objects unlike other primitive data types and are very easy to manipulate, removing anything from the middle is easy as well, completely dynamic.same with List and Stack
I don't know if you can change the size at runtime but you can allocate the size at runtime. Try using this code:
class MyClass {
void myFunction () {
Scanner s = new Scanner (System.in);
int myArray [];
int x;
System.out.print ("Enter the size of the array: ");
x = s.nextInt();
myArray = new int[x];
}
}
this assigns your array size to be the one entered at run time into x.
Here's a method that doesn't use ArrayList. The user specifies the size and you can add a do-while loop for recursion.
import java.util.Scanner;
public class Dynamic {
public static Scanner value;
public static void main(String[]args){
value=new Scanner(System.in);
System.out.println("Enter the number of tests to calculate average\n");
int limit=value.nextInt();
int index=0;
int [] marks=new int[limit];
float sum,ave;
sum=0;
while(index<limit)
{
int test=index+1;
System.out.println("Enter the marks on test " +test);
marks[index]=value.nextInt();
sum+=marks[index];
index++;
}
ave=sum/limit;
System.out.println("The average is: " + ave);
}
}
In Java Array Sizes are always of Fixed Length But there is way in which you can Dynamically increase the Size of the Array at Runtime Itself
This is the most "used" as well as preferred way to do it-
int temp[]=new int[stck.length+1];
for(int i=0;i<stck.length;i++)temp[i]=stck[i];
stck=temp;
In the above code we are initializing a new temp[] array, and further using a for loop to initialize the contents of the temp with the contents of the original array ie. stck[]. And then again copying it back to the original one, giving us a new array of new SIZE.
No doubt it generates a CPU Overhead due to reinitializing an array using for loop repeatedly. But you can still use and implement it in your code.
For the best practice use "Linked List" instead of Array, if you want the data to be stored dynamically in the memory, of variable length.
Here's a Real-Time Example based on Dynamic Stacks to INCREASE ARRAY SIZE at Run-Time
File-name: DStack.java
public class DStack {
private int stck[];
int tos;
void Init_Stck(int size) {
stck=new int[size];
tos=-1;
}
int Change_Stck(int size){
return stck[size];
}
public void push(int item){
if(tos==stck.length-1){
int temp[]=new int[stck.length+1];
for(int i=0;i<stck.length;i++)temp[i]=stck[i];
stck=temp;
stck[++tos]=item;
}
else
stck[++tos]=item;
}
public int pop(){
if(tos<0){
System.out.println("Stack Underflow");
return 0;
}
else return stck[tos--];
}
public void display(){
for(int x=0;x<stck.length;x++){
System.out.print(stck[x]+" ");
}
System.out.println();
}
}
File-name: Exec.java
(with the main class)
import java.util.*;
public class Exec {
private static Scanner in;
public static void main(String[] args) {
in = new Scanner(System.in);
int option,item,i=1;
DStack obj=new DStack();
obj.Init_Stck(1);
do{
System.out.println();
System.out.println("--MENU--");
System.out.println("1. Push a Value in The Stack");
System.out.println("2. Pop a Value from the Stack");
System.out.println("3. Display Stack");
System.out.println("4. Exit");
option=in.nextInt();
switch(option){
case 1:
System.out.println("Enter the Value to be Pushed");
item=in.nextInt();
obj.push(item);
break;
case 2:
System.out.println("Popped Item: "+obj.pop());
obj.Change_Stck(obj.tos);
break;
case 3:
System.out.println("Displaying...");
obj.display();
break;
case 4:
System.out.println("Exiting...");
i=0;
break;
default:
System.out.println("Enter a Valid Value");
}
}while(i==1);
}
}
Hope this solves your query.
You can do some thing
private static Person [] addPersons(Person[] persons, Person personToAdd) {
int currentLenght = persons.length;
Person [] personsArrayNew = Arrays.copyOf(persons, currentLenght +1);
personsArrayNew[currentLenght] = personToAdd;
return personsArrayNew;
}
You can create array with variable containing length. Like new int[n]. And pass n dynamically as argument to method. You can also create array with maximum size you can possibly need. And also create variable to track current size. depends on what your usage is.
i have this code snippet in my java application. i need to access the rule_body_arr_l2 outside the parent for loop. i tried to initialize the array outside the for loop but in the last line when i want to display its value, it says the array might not have been initialized yet.
String rule_body="person(?x),patientid(?y),haspid(?x,?y)";
System.out.println(rule_body);
String rule_body_arr[]=rule_body.split("\\),");
String rule_body_arr_l2[];
for(int x=0;x<rule_body_arr.length;x++)
{
System.out.println(rule_body_arr[x]);
rule_body_arr_l2=rule_body_arr[x].split("\\(");
System.out.println("LEVEL TWO SPLIT");
for(int y=0;y<rule_body_arr_l2.length;y++)
{
System.out.println(rule_body_arr_l2[y]);
}
}
for(int x=0;x<6;x++)
{
System.out.println(rule_body_arr_l2[x]);
}
Guidance is required in the matter
In Java, you must specify the array size. You haven't created an array. What you have done is, you have only created an array reference.
By default, in Java all references are set to null when initializing.
You must instantiate an array by giving an exact size for it.
For example,
int[] numberArray = new int[5];
If I understand your question, rather than using a split to parse the String you could use a regular expression with a Pattern to parse your String with something like
String rule_body = "person(?x),patientid(?y),haspid(?x,?y)";
Pattern p = Pattern.compile("person\\((.+)\\),patientid\\((.+)\\),haspid\\((.+)\\)");
Matcher m = p.matcher(rule_body);
if (m.matches()) {
System.out.printf("person = %s%n", m.group(1));
System.out.printf("patientid = %s%n", m.group(2));
System.out.printf("haspid = %s%n", m.group(3));
}
Which outputs
person = ?x
patientid = ?y
haspid = ?x,?y
If so then initialize rule_body_arr_l2 like
String[] rule_body_arr_l2 = new String[YOUR_POSSIBLE_LENGTH];
If you are not sure the length of String in prior declaration then better using ArrayList<String> like
ArrayList<String> rule_body_arr_l2= new ArrayList<String>();
try splitting at ), u wont get the comma problem
Reading the first answer in the Passing a String by Reference in Java? I (as on old pointer freaked C nerd) have a question regarding using arrays as pointers in java.
I have a variably number of EditText boxes in a setup routine for a n number of strings to be stored. This includes a add one EditText box button. So on screen the button is followed by a n number of EditText boxes. I have a similar for URLs to be stored.
Instead of having the same like 20 lines of code repeated over and over again for different such setup data items it is quite obviously a case for a method (function in C) and the issue is how do I keep the information about what EditText boxes are created when the user is pushing the Save button. In C you just send a pointer of an array of editboxes and realloc the editboxes array if new editboxes are created. In Java I can't realloc a the editboxes array to expand it but can create and clone it. But then it is not the same the editboxes array. But then I have the old editboxes array in the calling method and not the new. But obviously with Strings it is possible to make a String array array of one unit and send to the method and get it updated. This is obviously possible to be used with editboxes arrays as well, making an editboxes array array of one editboxes array that could be updated by the called method and expanded.
String[][] stringList = new String[1][];
stringList[0] = new String[2];
stringList[0][0] = new String("Sonny");
stringList[0][1] = new String("Ronny");
ExpandArray(context, stringList);
public static void ExpandArray(Context context, String[][] stringPtr) {
stringPtr[0][1]="Zeke";
String[] strings = new String[3];
System.arraycopy(stringPtr[0], 0, strings, 0, stringPtr[0].length);
stringPtr[0] = strings;
stringPtr[0][2]="Sue";
}
and
EditText[][] EditTextList = new EditText[1][];
EditTextList[0] = new EditText[2];
EditTextList[0][0] = new EditText(context);
EditTextList[0][1] = new EditText(context);
ExpandArray(context, EditTextList);
public static void ExpandArray(Context context, EditText[][] EditTextPtr) {
EditText[] EditTexts = new EditText[3];
System.arraycopy(EditTextPtr[0], 0, EditTexts, 0, EditTextPtr[0].length);
EditTextPtr[0] = EditTexts;
EditTextPtr[0][2]== new EditText(context);
}
Question 1 Reading the first answer in the Passing a String by Reference in Java? all comments are in strong favour of the two first StringBuilder solutions, but with no explanation why. That is Strings here we are talking about class arrays, might be different. *I feel I just made a C-solution in Java syntax and there might be some better Java culture solutions? You know C nerds are crazy about pointers to pointers etc and this smells such. *
Are there any better solutions for class arrays than arrays (solution 3)?
I am learning Java culture and my actual method of a button and n number of EditText boxes (works fine), but feel like garage culture:
public static LinearLayout TextListbox(Context context, EditText[][] EditTextboxes, String Title, String DataStringsDimension) {
final Context contextTextListbox = context;
final EditText[][] EditboxTextListbox=EditTextboxes;
final String ItemText = Title;
final LinearLayout layoutEditTextListbox = new LinearLayout(contextTextListbox);
layoutEditTextListbox.setOrientation(LinearLayout.VERTICAL);
layoutEditTextListbox.setX(layoutEditTextListbox.getX() + 15);
layoutEditTextListbox.setBackgroundColor(Color.rgb(0xFF, 0xE8, 0xAA));
if (DataStringsDimension != null)
EditboxTextListbox[0] = new EditText[getJniListDataSize(DataStringsDimension)];
else
EditboxTextListbox[0] = new EditText[0];
final Button button = new Button(contextTextListbox);
button.setText("+ " + ItemText);
button.setTag(EditboxTextListbox[0].length);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Enlarge to Edit box array
EditText[] EditboxArrayTemp = new EditText[EditboxTextListbox[0].length + 1];
System.arraycopy(EditboxTextListbox[0], 0, EditboxArrayTemp, 0, EditboxTextListbox[0].length);
EditboxTextListbox[0] = EditboxArrayTemp;
// Register a new edit box
EditboxTextListbox[0][EditboxTextListbox[0].length - 1] = new EditText(contextTextListbox);
EditboxTextListbox[0][EditboxTextListbox[0].length - 1].setHint(ItemText);
EditboxTextListbox[0][EditboxTextListbox[0].length - 1].setInputType(InputType.TYPE_CLASS_TEXT);
layoutEditTextListbox.addView(EditboxTextListbox[0][EditboxTextListbox[0].length - 1]);
}
});
layoutEditTextListbox.addView(button);
if (EditboxTextListbox[0].length > 0) {
String[] DataStrings = getJniTextUnceListData(DataStringsDimension);
for (int iSlotTitle = 0; iSlotTitle < EditboxTextListbox[0].length; iSlotTitle++) {
EditboxTextListbox[0][iSlotTitle] = new EditText(contextTextListbox);
EditboxTextListbox[0][iSlotTitle].setText(DataStrings[iSlotTitle]);
EditboxTextListbox[0][iSlotTitle].setTag(DataStrings[iSlotTitle]);
EditboxTextListbox[0][iSlotTitle].setHint(ItemText);
EditboxTextListbox[0][iSlotTitle].setInputType(InputType.TYPE_CLASS_TEXT);
layoutEditTextListbox.addView(EditboxTextListbox[0][iSlotTitle]);
}
}
return layoutEditTextListbox;
}
Question 2 It certainly be improved as Java culture? Any smart ideas?
I have it as a method in the SetupDlg class of mine, any reason to make such a thing its own class?
There might be some better ideas of how to make a setup edit for n number of text strings to be edited?
You can just use ArrayList instead of Array. Array has a fixed size, but ArrayList can grow easily. Equivalent to this:
String[][] stringList = new String[1][];
stringList[0] = new String[2];
stringList[0][0] = new String("Sonny");
stringList[0][1] = new String("Ronny");
ExpandArray(context, stringList);
public static void ExpandArray(Context context, String[][] stringPtr) {
stringPtr[0][1]="Zeke";
String[] strings = new String[3];
System.arraycopy(stringPtr[0], 0, strings, 0, stringPtr[0].length);
stringPtr[0] = strings;
stringPtr[0][2]="Sue";
}
will be:
List<List<String>> stringList = new ArrayList<List<String>>();
stringList.add(new ArrayList<String>());
stringList.get(0).add(new String("Sonny"));
stringList.get(0).add(new String("Ronny"));
ExpandArray(context, stringList);
//Instead of expand array
stringList.get(0).add(new String("Sue"));
For editText just use:
List<List<EditText>> editText = new ArrayList<List<EditText>>()
The size of ArrayList increases as required.
And about passing by reference, in java everything is passed by value. Only class objects are passed by reference. So only if you pass a class object and modify it, the change will be reflected outside the function.
For strings you can use string builders or String objects but if its only one string following works as well:
void main(){
string txt = "foo";
txt = addString(txt);
System.out.println(txt);
}
String addString(String txt)
{
txt += " bar";
}
The output will be : foo bar
Hope this helps!!
I have created two arrays with values in them.
String[] array1 = {"ab", "bc", "ca"};
String[] array2 = {"zy", "yx", "xz"};
I would like to create a third array that obtains specific values from the two arrays.
{"ab", "ca", "yx"}
Instead of simply merging two arrays, is there a way that I can pluck specific values from other arrays when creating the third array?
In Java
You would need to define an interface by which you decide which item is specific and which is not.
public interface SpecificItemDetect{
boolean isSpecific(String item);
}
Now, you can use this code to create your third array.
List<String> third = new ArrayList<String>();
for (String item : Array1){
if(detector.isSpecific(item)){
third.add(item);
}
}
for (String item : Array2){
if(detector.isSpecific(item)){
third.add(item);
}
}
// Now, you may want to convert the list to array.
String[] thirdArray = new String[third.size()];
third.toArray(thirdArray);
Note: detector in this example is an implementation of a class which implements the interface SpecificItemDetect.
In JavaScript
In JavaScript you would need a function instead of that interface. Something like this:
var filter = function(item){
if(/* item is specific */){
return true;
} else {
return false;
}
}
And create the third array like this:
var third = [];
for (var i = 0, len = Array1.length; i < len; i += 1){
if(filter(Array1[i])){
third.push(item);
}
}
for (var i = 0, len = Array2.length; i < len; i += 1){
if(filter(Array2[i])){
third.push(item);
}
}
You cannot access the memory where the array values are stored. This means, you need to go through the array name. Now, with array name you can refer to a specific value you want to 'pluck'. Do you have any rules for this??
Well, I'm not entirely sure what you mean when you say specific values, but if you mean the values that you showed only then you can do it this way
String[] array1 = {"ab", "bc", "ca"};
String[] array2 = {"zy", "yx", "xz"};
List<String> list1 = new ArrayList<String>();
String[] array3 = new String[list1.size()]; //Skip if you don't need array
list1.add(array1[0]);
list1.add(array1[2]);
list1.add(array2[1]);
list1.toArray(array3); //Skip if you don't need array
Much like what abforce said, but if you simply wanted to know how to use the .add method, that is all you need to do. But if you would like to change the values inside when the "specific values" you need change then the interface will be much better. This code is simiple but not very flexible if you need to change the values in the future.
I created a method that puts the read numbers into a NumberArray and in total 2 NumberArrays are created per input file. I have created an array of the object NumberRow on the line I marked with "!!!!". I put the read double into the array. However, when I read those arrays, numberRow[0] is not correct; all the values belonging in numberRow[1] are in there, and the values in numberRow[1] are correct. There is probably a simple solution, but I really don't see what is going wrong here.
Unit[] unitArray = new Unit[dataset.numberOfRecords];
double[] emptyDoubleArray = new double[dataset.numberOfRecords];
for(int x = 0; x<dataset.numberOfVariables; x++){
numberRow[x] = new NumberRow(emptyDoubleArray);
}
for(int i = 0; i<dataset.numberOfRecords; i++){
String label = in.next();
double[] elementsPerUnit = new double[dataset.numberOfVariables];
for(int k = 0; k<dataset.numberOfVariables; k++){
double misc = in.nextDouble();
!!!!! numberRow[k].NumberArray[i] = misc;
elementsPerUnit[k] = misc;
}
unit = new Unit(label, elementsPerUnit);
unitArray[i] = unit;
}
unitRow = new UnitRow(unitArray);
out.print(Arrays.toString(numberRow[0].NumberArray));
}
Arrays are objects in Java. That is, they are not copied and passed by value (like int, etc), they are passed by reference (like Object, String...)
If you create an array with new and pass it to two objects, there is still only one array (you only used new once, think about it this way). When one object edits the array, the single copy of the array, having been edited, 's edits are seen by the other object.
The solution is, create a new array if it should be distinct from all other arrays.
EDIT: You create one array here (note the new)
double[] emptyDoubleArray = new double[dataset.numberOfRecords];
this one array is passed to all NumberRows (note, no new)
numberRow[x] = new NumberRow(emptyDoubleArray);
therefore if I edit any NumberRow's array it is seen in all NumberRows.