• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arraylist memory transfer Issue (to new class)  RSS feed

 
Munto Bunes
Greenhorn
Posts: 14
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been trying to finish a three step process of bringing a working list to an actionListener class where it will be used to grab the name (ill figure that part out later as it will give more then just the name of the object -.-) but here is the issue: The memory of the original list is lost during the process and comes out to null in the new list. I've tried hours of trying to find the solution online but I'm giving up that method and trying here for an explanation :P.

ActionListener class:



Language class:



Any help would be awesome thanks .
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 1 in both of your classes defines a List<JRadioButton>. Each one has its own memory. You are not sharing the contents between the two anywhere.
 
Munto Bunes
Greenhorn
Posts: 14
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried:

//this.languages = language.getList();
//this.languages = new ArrayList<JRadioButton>(language.getList());
//this.languages = new ArrayList<JRadioButton>(m);

None works which I was told where supposed to work in the actionListener class replacing this.languages = language.getList();
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please post the entire set of code, including your main() method, so that I could compile it and run it myself.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please clean up your class/variable/method names. By convention, class names begin with an upper case letter. Variable and method names  start with a lower case letter.
 
Munto Bunes
Greenhorn
Posts: 14
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator








(That's the minimum you should need to run it)
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good grief. I had to hack it to get it to compile. See comments.

You can't instantiate an interface such as ActionListener. Looks like you meant to extends AbstractAction.

JRadioButton.getName() doesn't return anything unless you've set it to something using setName().

You were missing this in your actionListener (bad bad name) constructor
languages = m;

Really need to follow naming conventions, not doing so leads people to believe you're not putting much effort into it.


 
Munto Bunes
Greenhorn
Posts: 14
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you so much. I didn't know I couldn't instantiate an ActionListener. Sorry for all the trouble, I'm still learning and teaching myself java so this did a great deal to help me learn from my mistakes.
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.

Here's some comments regarding cleaning up the code a bit.


Variable names should not contain underscores, instead use camel case.
mainMenuPanel

"mainMenu()" should return a JPanel to avoid cast.


Booleans are very often name with a leading "is", such as "isMainMenu".


These are constants and as such should be declared "private static final" and their names should be in all caps. Here is one place that using underscores is the convention.


"Options" is a variable and therefore should begin with a lower case character. I would prefer "optionButton".


"Languages" should begin with lower case. I would prefer languageButtonGroup. Verbose names help with future maintenance.


"actionListener" is a class and should begin with an upper case letter, this, however, would conflict with a Java interface. Suggest "LanguageAction" or something similar.

Hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!