aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes can't I take a single array for JTextField and JTextArea as both are derived from JTextComponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "can Watch "can New topic
Author

can't I take a single array for JTextField and JTextArea as both are derived from JTextComponent

Kr. Pallav
Ranch Hand

Joined: Mar 06, 2010
Posts: 32

Below is the piece of code I am trying

The program compiles well but throws java.lang.ArrayStoreException: javax.swing.JTextArea
I know the reason is I am storing two different object JTextFiled and JTextArea to single array it is coming like that but both JTextField and JTextArea are derived from JTextComponent can't I take a single array
, why to take two different array for them.
Is there any alternate way to do it in a single array .


~|>@//@\/~
Kumar Pallav
-------------------
SCJP 5: 86 %, SCWCD: 91%
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

There's the problem. You have declared it as an array of JTextComponents, but in reality it's an array of JTextFields. Change the initialization to new JTextComponent[...] and you should be fine.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kr. Pallav
Ranch Hand

Joined: Mar 06, 2010
Posts: 32

Dear Rob Prime , I am really sorry for doing such silly mistake , and I am really thankful to you for replying and giving your time to me , It was such a silly mistake .

Thanks a lot ,God Bless

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can't I take a single array for JTextField and JTextArea as both are derived from JTextComponent