• Post Reply Bookmark Topic Watch Topic
  • New Topic

Modified Array Lists  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I'm having trouble with my program (Yet again)

My program is a JavaFX program. It uses FXML files which all serve a basic function, e.g. log in, navigate program, create a new user etc.

I'm having difficulty creating a new user, storing said user into an array-list and keeping said user.

I believe the problem occurs whenever I access the FXML file, ideally I would initialise the array-list when the program starts.

Is there a way to access and add to an array list without creating a new instance of a class or only create one instance when the program is running?

The array-list and more importantly the modified array-list needs to be accessed from various classes and stay the same unless a new user is created or modified.    

Here's my code.

Class AdminUserController




 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class UserData



Class Users



I would ideally like my program to be able to get a modified array-list and access it contents.

I however don't seem to be able to get the contents of the array-list in another class whenever I add new users using the program.

Please ignore the messy and names.

I plan on making changes to the names after I've fixed these issues. (I've been spending days on this ;~;)

The code has been shorten down so I could post it.

Any help would be very helpful.
 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had to short the code, the variables are there and such and everything works(To an extent)
 
Rancher
Posts: 2350
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can the code be compiled so it can be executed for testing?  For example the import statements are missing on the first class so it won't compile.

Can the UserData class create and populate the ArrayList in its constructor?


Every time createUser() is called another 4 items are added to the list.
 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code has been formatted to allow me to post, the imports are there.

UserData is able to create and populate.

And whenever the user enters the correct inputs and clicks the button, the createUser creates 4 items.
ID, UserName, passWord, userType.

The problem is being able to keep that whenever I need it again.

When UserData callClass = New UserData is called, I believe it is creating a new instance of class and therefore getting rid of the new user which is created.

I plan on creating a new instance in main so whenever the program is started all the data will be available and will only be replaced/overwritten when the program ends. 

 
Norm Radder
Rancher
Posts: 2350
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the imports are there. 


Sorry I don't see any import statements.  Without them the code can not be compiled for testing.


Can you make a small, complete, simple program that compiles and executes and shows the problem? 
 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Norm Radder
Rancher
Posts: 2350
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you make a small, complete, simple program that compiles and executes and shows the problem?

The use of JavaFX and files just complicates the program and is probably not part of the problem.  The simplest possible program would make it easier to work on.


Does that code compile without errors?  All the )))))s on line 74 doesn't look right.
 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've decided to print myUsers to show the problem.

On button click, this is printed out.
[BunnyCorp.Classes.Users@6a59974d , BunnyCorp.Classes.Users@3031d343, BunnyCorp.Classes.Users@9b7b592, BunnyCorp.Classes.Users@40dbc4e]

While staying on the same FXML and clicking this is printed
[BunnyCorp.Classes.Users@6a59974d , BunnyCorp.Classes.Users@3031d343, BunnyCorp.Classes.Users@9b7b592, BunnyCorp.Classes.Users@40dbc4e]

However when I leave the FXML and go back and click, this is printed

First click
null

Second click
[BunnyCorp.Classes.Users@6c29e8a9, BunnyCorp.Classes.Users@48f4998e, BunnyCorp.Classes.Users@69917607, BunnyCorp.Classes.Users@1a9f05e9]

Third click
[BunnyCorp.Classes.Users@6c29e8a9, BunnyCorp.Classes.Users@48f4998e, BunnyCorp.Classes.Users@69917607, BunnyCorp.Classes.Users@1a9f05e9]

Ideally, I would prefer whenever I leave or go back to the FXML, it should print the same values, plus the same values of a created user.



 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh the extra ))))))) is because I had to remove some text, this is a minimalist version of my program. I must have forgotten to remove them when attempting to post the code on here.
 
Norm Radder
Rancher
Posts: 2350
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you make a small, complete, simple program that compiles and executes and shows the problem?

The use of JavaFX and files just complicates the program and is probably not part of the problem.  The simplest possible program would make it easier to work on.

I must have forgotten to remove them when attempting to post the code on here. 


Posting code that you have not compiled and fixed any errors before posting wastes everyone's time.
 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to recreate the program that doesn't use JavaFX/FMXLs

The code above is a slimmed down version of the code I'm actually using. Because of the character limit, I was unable to post the full code. I slimmed it down, I forgot to remove some extra brackets.

The problem occurs when I change FXML scenes.

When I start the program and click the button, this is printed

null
Username validation has found no duplicates in memory
Unable to create new user

When I click it again this is printed.

[BunnyCorp.Classes.Users@7865ab91, BunnyCorp.Classes.Users@61d97e57, BunnyCorp.Classes.Users@6e182e5d, BunnyCorp.Classes.Users@76fc4319, BunnyCorp.Classes.Users@23905774, BunnyCorp.Classes.Users@991be97, BunnyCorp.Classes.Users@2654133e, BunnyCorp.Classes.Users@32246866, BunnyCorp.Classes.Users@13aeb2a1, BunnyCorp.Classes.Users@174fc345]
Username validation has found no duplicates in memory
Unable to create new user

If I click it again this is printed.
[BunnyCorp.Classes.Users@7865ab91, BunnyCorp.Classes.Users@61d97e57, BunnyCorp.Classes.Users@6e182e5d, BunnyCorp.Classes.Users@76fc4319, BunnyCorp.Classes.Users@23905774, BunnyCorp.Classes.Users@991be97, BunnyCorp.Classes.Users@2654133e, BunnyCorp.Classes.Users@32246866, BunnyCorp.Classes.Users@13aeb2a1, BunnyCorp.Classes.Users@174fc345, BunnyCorp.Classes.Users@1184ef71, BunnyCorp.Classes.Users@f2d27f, BunnyCorp.Classes.Users@662f537a, BunnyCorp.Classes.Users@f13f111, BunnyCorp.Classes.Users@39da78e5, BunnyCorp.Classes.Users@2f2d248b, BunnyCorp.Classes.Users@33051697, BunnyCorp.Classes.Users@238ee29f, BunnyCorp.Classes.Users@49f9bb5b, BunnyCorp.Classes.Users@fb6d793, BunnyCorp.Classes.Users@bffcfab, BunnyCorp.Classes.Users@330fc02, BunnyCorp.Classes.Users@76b2f76, BunnyCorp.Classes.Users@6bb37d80, BunnyCorp.Classes.Users@1ec475ca, BunnyCorp.Classes.Users@1a104afc, BunnyCorp.Classes.Users@44dec657, BunnyCorp.Classes.Users@34f1fc31, BunnyCorp.Classes.Users@9a6a540, BunnyCorp.Classes.Users@11795922]
Username validation has found no duplicates in memory

If I click it again after filling the text-fields with the correct info this is printed.
[BunnyCorp.Classes.Users@7865ab91, BunnyCorp.Classes.Users@61d97e57, BunnyCorp.Classes.Users@6e182e5d, BunnyCorp.Classes.Users@76fc4319, BunnyCorp.Classes.Users@23905774, BunnyCorp.Classes.Users@991be97, BunnyCorp.Classes.Users@2654133e, BunnyCorp.Classes.Users@32246866, BunnyCorp.Classes.Users@13aeb2a1, BunnyCorp.Classes.Users@174fc345, BunnyCorp.Classes.Users@1184ef71, BunnyCorp.Classes.Users@f2d27f, BunnyCorp.Classes.Users@662f537a, BunnyCorp.Classes.Users@f13f111, BunnyCorp.Classes.Users@39da78e5, BunnyCorp.Classes.Users@2f2d248b, BunnyCorp.Classes.Users@33051697, BunnyCorp.Classes.Users@238ee29f, BunnyCorp.Classes.Users@49f9bb5b, BunnyCorp.Classes.Users@fb6d793, BunnyCorp.Classes.Users@bffcfab, BunnyCorp.Classes.Users@330fc02, BunnyCorp.Classes.Users@76b2f76, BunnyCorp.Classes.Users@6bb37d80, BunnyCorp.Classes.Users@1ec475ca, BunnyCorp.Classes.Users@1a104afc, BunnyCorp.Classes.Users@44dec657, BunnyCorp.Classes.Users@34f1fc31, BunnyCorp.Classes.Users@9a6a540, BunnyCorp.Classes.Users@11795922]
Username validation has found no duplicates in memory

If I click it again, this is printed.
[BunnyCorp.Classes.Users@2abbf2e5, BunnyCorp.Classes.Users@7865ab91, BunnyCorp.Classes.Users@61d97e57, BunnyCorp.Classes.Users@6e182e5d, BunnyCorp.Classes.Users@76fc4319, BunnyCorp.Classes.Users@23905774, BunnyCorp.Classes.Users@991be97, BunnyCorp.Classes.Users@2654133e, BunnyCorp.Classes.Users@32246866, BunnyCorp.Classes.Users@13aeb2a1, BunnyCorp.Classes.Users@174fc345, BunnyCorp.Classes.Users@1184ef71, BunnyCorp.Classes.Users@f2d27f, BunnyCorp.Classes.Users@662f537a, BunnyCorp.Classes.Users@f13f111, BunnyCorp.Classes.Users@39da78e5, BunnyCorp.Classes.Users@2f2d248b, BunnyCorp.Classes.Users@33051697, BunnyCorp.Classes.Users@238ee29f, BunnyCorp.Classes.Users@49f9bb5b, BunnyCorp.Classes.Users@fb6d793, BunnyCorp.Classes.Users@bffcfab, BunnyCorp.Classes.Users@330fc02, BunnyCorp.Classes.Users@76b2f76, BunnyCorp.Classes.Users@6bb37d80, BunnyCorp.Classes.Users@1ec475ca, BunnyCorp.Classes.Users@1a104afc, BunnyCorp.Classes.Users@44dec657, BunnyCorp.Classes.Users@34f1fc31, BunnyCorp.Classes.Users@9a6a540, BunnyCorp.Classes.Users@11795922, BunnyCorp.Classes.Users@82e8765, BunnyCorp.Classes.Users@408dcf7, BunnyCorp.Classes.Users@3e96948f, BunnyCorp.Classes.Users@4bcf7562, BunnyCorp.Classes.Users@3726d6d1, BunnyCorp.Classes.Users@758b5ba6, BunnyCorp.Classes.Users@7fb38b74, BunnyCorp.Classes.Users@4f678585, BunnyCorp.Classes.Users@4ef652e6, BunnyCorp.Classes.Users@618f76f5]
Username validation has found no duplicates in memory
Unable to create new user

Now If I were to click on another button and go to another FXML and then back to the UserCreation FXML all these value will be different.

The problem is, if I would ideally like what's in bold while I'm running the program. The values of the object shouldn't change unless I were to close/restart the program.

I'm trying to get the values within the array-list to stay the same including the values of a newly added object in the array-list.

However I don't know how to go about this.

The code I've provided is incomplete, but is a representation of what I'm trying to work with.

I'm asking on how to create an array-list add to it, and use the new array-list without replacing the objects or their values so I can access the newer objects and the predefined ones too.










 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The is what is printed when I do the same thing after switching FXMLs

Button clicked: 1

null
Username validation has found no duplicates in memory
Unable to create new user

Button clicked 2:

[BunnyCorp.Classes.Users@3142fe53, BunnyCorp.Classes.Users@502f39e0, BunnyCorp.Classes.Users@1b79c530, BunnyCorp.Classes.Users@4c60bef6, BunnyCorp.Classes.Users@6a76714f, BunnyCorp.Classes.Users@433fa5d8, BunnyCorp.Classes.Users@16baa8ca, BunnyCorp.Classes.Users@5fe433e5, BunnyCorp.Classes.Users@6c1dd5f, BunnyCorp.Classes.Users@38eea93a]
Username validation has found no duplicates in memory
Unable to create new user

Button clicked 3:
[BunnyCorp.Classes.Users@3142fe53, BunnyCorp.Classes.Users@502f39e0, BunnyCorp.Classes.Users@1b79c530, BunnyCorp.Classes.Users@4c60bef6, BunnyCorp.Classes.Users@6a76714f, BunnyCorp.Classes.Users@433fa5d8, BunnyCorp.Classes.Users@16baa8ca, BunnyCorp.Classes.Users@5fe433e5, BunnyCorp.Classes.Users@6c1dd5f, BunnyCorp.Classes.Users@38eea93a, BunnyCorp.Classes.Users@7bd1aa15, BunnyCorp.Classes.Users@554d591, BunnyCorp.Classes.Users@d77db41, BunnyCorp.Classes.Users@409d04ac, BunnyCorp.Classes.Users@366a8fa8, BunnyCorp.Classes.Users@15312ca9, BunnyCorp.Classes.Users@262f409d, BunnyCorp.Classes.Users@e3f9890, BunnyCorp.Classes.Users@6c4a5130, BunnyCorp.Classes.Users@70027c74]
Username validation has found no duplicates in memory
Unable to create new user

Button clicked 4: This time entered user details
[BunnyCorp.Classes.Users@3142fe53, BunnyCorp.Classes.Users@502f39e0, BunnyCorp.Classes.Users@1b79c530, BunnyCorp.Classes.Users@4c60bef6, BunnyCorp.Classes.Users@6a76714f, BunnyCorp.Classes.Users@433fa5d8, BunnyCorp.Classes.Users@16baa8ca, BunnyCorp.Classes.Users@5fe433e5, BunnyCorp.Classes.Users@6c1dd5f, BunnyCorp.Classes.Users@38eea93a, BunnyCorp.Classes.Users@7bd1aa15, BunnyCorp.Classes.Users@554d591, BunnyCorp.Classes.Users@d77db41, BunnyCorp.Classes.Users@409d04ac, BunnyCorp.Classes.Users@366a8fa8, BunnyCorp.Classes.Users@15312ca9, BunnyCorp.Classes.Users@262f409d, BunnyCorp.Classes.Users@e3f9890, BunnyCorp.Classes.Users@6c4a5130, BunnyCorp.Classes.Users@70027c74, BunnyCorp.Classes.Users@c0ca6e7, BunnyCorp.Classes.Users@1576d7c1, BunnyCorp.Classes.Users@271267c8, BunnyCorp.Classes.Users@3040b087, BunnyCorp.Classes.Users@599203f6, BunnyCorp.Classes.Users@7af91fda, BunnyCorp.Classes.Users@4ee10b6a, BunnyCorp.Classes.Users@7b905eb9, BunnyCorp.Classes.Users@32d46f8e, BunnyCorp.Classes.Users@e1b1c1]
Username validation has found no duplicates in memory

Button clicked 5: No details entered
[BunnyCorp.Classes.Users@1f3cd318, BunnyCorp.Classes.Users@3142fe53, BunnyCorp.Classes.Users@502f39e0, BunnyCorp.Classes.Users@1b79c530, BunnyCorp.Classes.Users@4c60bef6, BunnyCorp.Classes.Users@6a76714f, BunnyCorp.Classes.Users@433fa5d8, BunnyCorp.Classes.Users@16baa8ca, BunnyCorp.Classes.Users@5fe433e5, BunnyCorp.Classes.Users@6c1dd5f, BunnyCorp.Classes.Users@38eea93a, BunnyCorp.Classes.Users@7bd1aa15, BunnyCorp.Classes.Users@554d591, BunnyCorp.Classes.Users@d77db41, BunnyCorp.Classes.Users@409d04ac, BunnyCorp.Classes.Users@366a8fa8, BunnyCorp.Classes.Users@15312ca9, BunnyCorp.Classes.Users@262f409d, BunnyCorp.Classes.Users@e3f9890, BunnyCorp.Classes.Users@6c4a5130, BunnyCorp.Classes.Users@70027c74, BunnyCorp.Classes.Users@c0ca6e7, BunnyCorp.Classes.Users@1576d7c1, BunnyCorp.Classes.Users@271267c8, BunnyCorp.Classes.Users@3040b087, BunnyCorp.Classes.Users@599203f6, BunnyCorp.Classes.Users@7af91fda, BunnyCorp.Classes.Users@4ee10b6a, BunnyCorp.Classes.Users@7b905eb9, BunnyCorp.Classes.Users@32d46f8e, BunnyCorp.Classes.Users@e1b1c1, BunnyCorp.Classes.Users@334a98aa, BunnyCorp.Classes.Users@6460fd3, BunnyCorp.Classes.Users@3e253c86, BunnyCorp.Classes.Users@47f89c49, BunnyCorp.Classes.Users@2090c3d4, BunnyCorp.Classes.Users@161e6882, BunnyCorp.Classes.Users@148b7cb, BunnyCorp.Classes.Users@251797f, BunnyCorp.Classes.Users@24799482, BunnyCorp.Classes.Users@4146a2f7]
Unable to create new user

In bold is the new user





 
Norm Radder
Rancher
Posts: 2350
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[BunnyCorp.Classes.Users@3142fe53


That looks like the String returned by the Object class's toString method.
To get a more useful String add a toString method to the Users class that returns the String you want to see.

The posted code still has compiler errors.  Please compile code and fix the errors BEFORE posting it.
 
Sheriff
Posts: 4424
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you would like us to look at your complete class listings, you could create a free GitHub account and post them to a project.

Otherwise, try to create a SSCCE (that's a link) and post it here.
 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm not feeling well today, I'll be sure to update you tomorrow.

 
Alec Goodsir
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I've decided to pass the Array-List when I load the FXML and that seems to be working for me now. Not alot was changed rather I might delete UserData class and used getters.

Every class that requires the array creates an array, sets myUsers created in Main to myUsers array in the class using a getter.

 
Knute Snortum
Sheriff
Posts: 4424
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad you got it working.  If you want to post the relevant code, we could help you refine it more.  Otherwise, happy coding!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!