Slight Problem with arrays.

I have got two arrays. One for initializing and another for displaying. The display array always shows nothing if the initializing array has not been called. The problem now though is that if I want to insert something in a certain slot in the array nothing happens and I dont know why. Here is a sample code of my 3 arrays.

Don't create multiple threads for the same problem if you don't intend on reading the replies given in your previous threads. In this thread, you were given a thorough explanation of how arrays work; if you still don't get it then maybe this assignment is too tough for you.

don't use two arrays, just use one, for both initializing and printing.
also, in your

public void arr3(){
...
}

method, you are referring to Array arr, which is not declared within the method, and, I think after looking at your other methods, where it's passed as an argument, it's not declared in the class either (but is possible off course)

could you please show all your code and tell us what it is you do try to accomplish?

Don't create multiple threads for the same problem if you don't intend on reading the replies given in your previous threads. In this thread, you were given a thorough explanation of how arrays work; if you still don't get it then maybe this assignment is too tough for you.

I figured out on how to make the arrays work but I cant seem to find out why the values that have been stored in an array in a specific method cannot be seen in another. Maybe I just didnt get it right but like in the initial post, when displayed, the values in the display array are still having the initialized value even if a different method that assigns a different value to certain points is called.

ps. I used a different function to display the fields because i want to display the values at a time when I call the function

Unless you post a *complete* working code, there is no way we can *see* what's wrong on your code. If not that, then present a SSCE which explains your situation. Either that or use an IDE like Eclipse to help you in debugging your application.

I have posted an edited version of the original code. It compiles and runs and is evident of what I am trying to do. Please Ignore any inconsistancies or anything concerning classes and help out on the arrays. Thank you

You try to display something which you don't even process after declaring i.e. the local array `arr' declared in main(); hence the given result. Either pass the local variable `arr' to your class instances or write a display method which works on class members i.e. `arr' of Class1.

But come to think of it; this is possibly the one of the most ill designed class hierarchy I have ever seen; the naming conventions not being followed is yet another woe. Consider reading on some good material as mentioned in the Java forum sticky.

But come to think of it; this is possibly the one of the most ill designed class hierarchy I have ever seen; the naming conventions not being followed is yet another woe. Consider reading on some good material as mentioned in the Java forum sticky.

Like I had earlier mentioned this was just a draft code to show what I wanted to do and not the original one. Thank you for the suggestion on the array but I cant seem to figure out how to go about what you were talking about. If you could please explain with a simple example that would help alittle more. Thank you

Well the whole assignment is about a level of a game but at the moment I would only appreciate help with the array part and try to figure out the rest.

First Class- I am trying to initialize an array to a certain value to be a default value in this class. I also want a display method here. The display method should be called at anytime and contain the values in each array field.

Second Class- I want the user to input certain details like coordinates i.e rows and columns and assign a certain character to these coordinates.

Third Class- This should be the main. which is menu driven. calls the method that asks for user input and also the method to display.

Either pass the array reference declared in main() to your methods or just make sure that the display() method prints out the instance variable 'arr' instead of passing it an array declared in the main() method.

The above post is all in one class and not in different classes like I had wanted. Anyway I have done something and the code puts the mark where I want it to be. However, on a second loop to check if the previous mark was stored in the coordinates, it looks like the coordinates are reseted again to the new x and y values. Here is the code.

Again a lot of problems with your code.
- Don't create a `public' Scanner instance; use the `in' passed in the `in' method of class1 to create a Scanner , that's the entire point of passing in an InputStream .
- If you need to set something at the position x,y of your array, do it once, not in a loop. It is because of this loop that the previous values are getting wiped off. Also check the values of `x' and `y' to avoid ArrayIndexOutOfBoundsException .

Any reason why `class3' extends `class2' and `class3' has a reference to `class1'? Your design has a lot of coupling and almost no cohesion. Like I mentioned previously, reconsider your design choices, discuss with your peers and professors about this assignment and read some good tutorials/books.

I managed to figure out the array problem. Thanks alot. However, I now want to solve something different. I want a user to enter x and y values to get the details in those coordinates. I have created an array of objects that will be assigned to the 2D array but it seems to overwrite it. below is my sample code. Thanks for any help

That is how I get the problem. X and Y are input by the user in one method with attributes. What I want to do is to be able to prompt the user from another method for coordinates x,y and then display the attributes that were input earlier. My thought came up to the above code which overwrites. How can I overcome this?

I dont think the above does the trick. It looks like it gets the X and Y points and also their attributes maybe. What I want to do is after you get the X and Y points say (1,2), get user input and store the details in this point (1,2). Then when the user inputs (1,2) later for display not input, it displays the details in (1,2).

Then when the user inputs (1,2) later for display not input, it displays the details in (1,2).

That was the point of the skeletal code above. The details are the "Attribute" object. You can call it whatever you want. All you are doing is storing and retrieving a single object at a position in a 2D array.

Am sorry but am not getting this at all. I understand what you are saying and that is what I had in mind. But the details I want to store are in another method. So I dont know how to go about it. I cant even seem to figure out how to call it in the other method because if I do something like "array[x][y].attribute" I still dont get the result. I also created a new object to try out differently but to no avail.This is what I tried to do