Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    JavaNovice24 is offline Member
    Join Date
    Nov 2015
    Posts
    9
    Rep Power
    0

    Default Help! This error message refuses to go away!!

    Hey guys, I'm in a bit of a rut here. The code is simple, but I keep getting this error message and I can't seem to figure out how to resolve it. Any ideas? I've been at this for such a long time, any and all help is appreciated -- thanks!
    Attached Thumbnails Attached Thumbnails Help! This error message refuses to go away!!-screen-shot-2015-11-21-8.59.00-pm.png  
    Last edited by JavaNovice24; 11-22-2015 at 03:03 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help! This error message refuses to go away!!

    The message says what the problem is. What don't you understand about the message?

    What are you trying to do?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    JavaNovice24 is offline Member
    Join Date
    Nov 2015
    Posts
    9
    Rep Power
    0

    Default Re: Help! This error message refuses to go away!!

    I am trying to run this but I keep getting this message. I don't understand what it means, so I don't know how to resolve it. Can you help?

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,716
    Rep Power
    18

    Default Re: Help! This error message refuses to go away!!

    A good place to start reading a stack trace is from the top and going down until you hit a line that refers to your code. In this case it is

    Java Code:
    at Splat.main(Splat.java:10)
    This is the line that is giving rise to the error. And I'm guessing line 10 is this one:

    Java Code:
    frame.getContentPane().add(frame, new Splat());
    According to the API docs for the add() method "public void add(Component comp, Object constraints)
    Adds the specified component to the end of this container. Also notifies the layout manager to add the component to this container's layout using the specified constraints object. This is a convenience method for addImpl(java.awt.Component, java.lang.Object, int)."

    So what this line is doing is (a) taking the frame JFrame, (b) getting the content pane it contains and then (c) adding the frame to the content pane that it contains. The error message is saying that you can't do this: if A contains B then you simply can't put A inside B. Swing containers are like physical things like xmas presents in this regard.

    I agree with Norm's second question as JFrames aren't the sort of thing that you would usually want to put inside containers in the first place. Also I would point out that Oracle's Tutorial discusses numerous examples of how to set up Swing graphical user interfaces with JFrame being discussed quite early on.

  5. #5
    JavaNovice24 is offline Member
    Join Date
    Nov 2015
    Posts
    9
    Rep Power
    0

    Default Re: Help! This error message refuses to go away!!

    Quote Originally Posted by pbrockway2 View Post
    A good place to start reading a stack trace is from the top and going down until you hit a line that refers to your code. In this case it is

    Java Code:
    at Splat.main(Splat.java:10)
    This is the line that is giving rise to the error. And I'm guessing line 10 is this one:

    Java Code:
    frame.getContentPane().add(frame, new Splat());
    According to the API docs for the add() method "public void add(Component comp, Object constraints)
    Adds the specified component to the end of this container. Also notifies the layout manager to add the component to this container's layout using the specified constraints object. This is a convenience method for addImpl(java.awt.Component, java.lang.Object, int)."

    So what this line is doing is (a) taking the frame JFrame, (b) getting the content pane it contains and then (c) adding the frame to the content pane that it contains. The error message is saying that you can't do this: if A contains B then you simply can't put A inside B. Swing containers are like physical things like xmas presents in this regard.

    I agree with Norm's second question as JFrames aren't the sort of thing that you would usually want to put inside containers in the first place. Also I would point out that Oracle's Tutorial discusses numerous examples of how to set up Swing graphical user interfaces with JFrame being discussed quite early on.
    I understand what you are saying. You explained that very well. However, I still don't know how to solve this. It is so unclear to me, not obvious like it is to you guys. Can you help?

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Help! This error message refuses to go away!!

    You should code more in English:
    Java Code:
    I have a frame, on the contentPane I put a new Splat
         frame        .getContentPane()     .add( new Splat() )
    frame.getContentPane().add( new Splat() )
    The constraint that you can add as the second parameter depends on the LayoutManager you use.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help! This error message refuses to go away!!

    @SurfMan: that's not it: the OP is trying to add a JFrame to itself given a Splat as constraints (it doesn't make sense of course).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help! This error message refuses to go away!!

    @OP - The very first page of the JFrame API Doc says you can use the JFrame.add() method as a convenience method. You don't need to
    get the content pane. It seems to me that you are relatively new to Java so you may want to check out the tutorials (see my signature).
    I recommend you become familiar with the basics before attempting GUI programming.

    Regards,
    Jim
    Last edited by jim829; 11-22-2015 at 04:15 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    JavaNovice24 is offline Member
    Join Date
    Nov 2015
    Posts
    9
    Rep Power
    0

    Default Re: Help! This error message refuses to go away!!

    I'm not understanding what I should change here in order to successfully run the code. I looked at the tutorial but still can't figure it out.

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help! This error message refuses to go away!!

    what I should change
    Do not try to add a frame to itself.
    Can you explain what you are trying to do?
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help! This error message refuses to go away!!

    Quote Originally Posted by JavaNovice24 View Post
    I'm not understanding what I should change here in order to successfully run the code. I looked at the tutorial but still can't figure it out.
    We'll try it the other way around: what are you trying to add to that JFrame? (look at line #10 in your op).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  12. #12
    JavaNovice24 is offline Member
    Join Date
    Nov 2015
    Posts
    9
    Rep Power
    0

    Default Re: Help! This error message refuses to go away!!

    I am trying to get this output:

    Help! This error message refuses to go away!!-screen-shot-2015-11-22-11.49.19-am.png

  13. #13
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,995
    Rep Power
    9

    Default Re: Help! This error message refuses to go away!!

    Quote Originally Posted by JosAH View Post
    @SurfMan: that's not it: the OP is trying to add a JFrame to itself given a Splat as constraints (it doesn't make sense of course).
    kind regards,
    Jos
    I sawthe mistake. I am under the assumption that he wants to add a Splat to a JFrame. My code explains exactly that. If you write in English what he wrote in code then you'd get:
    I have a frame, on the contentPane I put this frame with a new Splat as constraints
    That makes it sound wrong. I was hoping he got that message. But if even *you* didn't get that, I will probably have failed :)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help! This error message refuses to go away!!

    Quote Originally Posted by JavaNovice24 View Post
    I am trying to get this output:
    But now you're adding a 'SplatPanel' to the JFrame; in your original post you were trying to add the JFrame itself to the JFrame and that's were the JVM started complaining ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  15. #15
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help! This error message refuses to go away!!

    I decided to do a search and found the following site:

    http://www.csc.villanova.edu/~map/10...p04/Splat.java

    It is safe to open since it is just a text file. I tried to back up to Chap04 and it is protected. However, if you try
    to open SplatPanel.java in the same directory you get the required class.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  16. #16
    JavaNovice24 is offline Member
    Join Date
    Nov 2015
    Posts
    9
    Rep Power
    0

    Default Re: Help! This error message refuses to go away!!

    It is giving me an issue with java.awt ... Even after I remove the import and just leave javax.swing, the error remains the same: Help! This error message refuses to go away!!-screen-shot-2015-11-22-12.36.16-pm.png
    I appreciate all of you guys' help thus far. Your comments have been very useful, but maybe I am just missing something. I have been at this for days and it is very frustrating. Can anyone provide a solution?
    Last edited by JavaNovice24; 11-22-2015 at 11:36 PM.

  17. #17
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help! This error message refuses to go away!!

    All you did was rename the class to SplatPanel. You didn't read what I said. You need two classes. Splat and SplatPanel. I think you should really start anew and study the basics before you do any graphics stuff.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  18. #18
    JavaNovice24 is offline Member
    Join Date
    Nov 2015
    Posts
    9
    Rep Power
    0

    Default Re: Help! This error message refuses to go away!!

    I need to run this for my class. I am aware that i need to learn the basics. But for now, I don't have the time to catch up on that.

  19. #19
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help! This error message refuses to go away!!

    Re-read the posts on this thread. It was explained and sample code was given. Did you try any of them?
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Help! This error message refuses to go away!!

    Quote Originally Posted by JavaNovice24 View Post
    I need to run this for my class. I am aware that i need to learn the basics. But for now, I don't have the time to catch up on that.
    Did the teacher give any instructions? Perhaps you should ask him/her about it.

    Edit: Looks like you also need the Circle.java class at the same site.

    Regards,
    Jim
    Last edited by jim829; 11-23-2015 at 01:22 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Page 1 of 2 12 LastLast

Similar Threads

  1. help me with this error message
    By joel7 in forum New To Java
    Replies: 1
    Last Post: 11-27-2012, 08:10 AM
  2. Replies: 3
    Last Post: 10-10-2012, 07:34 PM
  3. JApplet works in eclipse but refuses to show online
    By Reskaillev in forum New To Java
    Replies: 14
    Last Post: 09-10-2011, 01:36 PM
  4. 'else' without 'if' error message
    By jim01 in forum New To Java
    Replies: 6
    Last Post: 04-22-2011, 09:10 PM
  5. Error Message????
    By Cubba27 in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •