Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kr. Pallav
Ranch Hand
Posts: 32
Eclipse IDE Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic