This program should accept a donors name, phone number, charity, and abount in a GUI frame. The basic framwork is done, but compile time throws an illegal argument of cannot add parent to itself. I am sooo a greenhorn and searching the 'net has resulted in loss of hair. The code is below. P.S. How do I add code to this thread?
Please also post the error message and stack trace, copied and pasted just as it appears on your end. Part of the 'service' is to help you interpret, understand, and respond to error messages. (And having the error message should save us the usually minor trouble of running the code.)
Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
Thank all of you hard-working, underpaid, geniuses who contribute to the education of my 2 brain cells. Could you tell me how you putthe code in? I am confused in how you got the line numbers. Here is the stack trace and error codes.
Exception in thread "main" java.lang.IllegalArgumentException: adding container's parent to itself
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
I did not repost the code because of the issue in the first paragraph, and it is already there, but if it will help then I will post it again.
The stack trace that caused the error is beneath. I prefer to start at the bottom, looking for references to my code in each line that starts with an 'at'. There will also be references to other code, usually core Java classes and methods, but they can be to any other code imported to make your code complete.
Inverting your stack trace:
142 is the line in your main() method that calls the CharityPledgeProgramGUI() constructor,
50 is the line that starts with add then continues on the next few lines:
Component add = charityPanel.add(charityPanel); // <-- three code lines put together, lines 49, 50 and 52
After that, the stack trace references code that you didn't write, all in the class called Container. So, the problem code must be in that line 50 (or lines 49 - 52). As pointed out earlier, those lines say to add charityPanel to charityPanel. Uhmmmm. That sounds like the error message, "adding container's parent to itself." Apparently, that's not a good thing.
So you know what's wrong, but we don't know what you were trying to do to help you fix it. What did you have in mind there?
Maybe you meant to return a JPanel from buildPanel() and then add that to the JFrame. (?)
You are correct in that I was trying to add the panel to the frame. I removed the first charityPanel from the charityPanel.add (charityPanel) and the file compiles with errors, but it compiles and does not throw any red error messages. The panel now builds and displays. Thanks for you help. Now all I have to do is have it print the text fields to the text area at the bottom and print to a file. More learning...