• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can anybody help with exception

 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I am trying to run a applet using CarLayout ..
But the file gets compiled and when i try to view it, it gives me init() not initialized.
The error i get on dos is :
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to layout: constraint must be a string
at java.awt.CardLayout.addLayoutComponent(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at Step1.panelStep2of5(GtraceStep1.java:233)
at Step1.init(GtraceStep1.java:88)
at Step1.main(GtraceStep1.java:314)
Can anybody tell me where is the problem ......... how do i rectify.....
Please help me
I have one more query which i have posted ....its about Panel, Layouts, & Frame
if possible do reply to that too...
Kajol

[This message has been edited by Kajol Shroff (edited March 05, 2001).]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am not sure what your code looks like, but when you add a component to a CardLayout you should specify a name string for the card.
add( "FirstCard", firstCard );
Manfred.
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manfred,
I tried but now it gives me:
Exception in thread "main" java.lang.IllegalArgumentException: cannot add to lay
out: constraint must be a string
at java.awt.CardLayout.addLayoutComponent(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at GtraceStep1.panelStep2of5(GtraceStep1.java:236)
at GtraceStep1.init(GtraceStep1.java:90)
at GtraceStep1.main(GtraceStep1.java:318)
Now this error
Help me
Kajol
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I am waiting for your reply...
Please help me out....
Kajol
 
Jahanzeb Sayal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
posting code will help...
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jahanzeb Sayal,
I already got the probelm with the exception solved..
Thanks a lot for replying ...
Keep in touch ..
Kajol
 
Hernan Eche
Greenhorn
Posts: 6
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajol Shroff wrote:Thanks Jahanzeb Sayal,
I already got the probelm with the exception solved..
Thanks a lot for replying ...
Keep in touch ..
Kajol


What was the solution?? (in ten year nobody asked it... )
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure Manfred Leonhardt's suggestion was correct, and the poster was simply passing the wrong kind of object as a constraint. His "I tried that, but..." message was presumably a mistake on his part.
 
Hernan Eche
Greenhorn
Posts: 6
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sherlock, that seems to be the case .. On the other hand, I've tried it but without success..

This is how to reproduce the same exception in Netbeans 7.0

Create a Project, add a JFrame, select AbsoluteLayer, insert a jTabbedPane1.. then adding a inner class like this (to load moving gif)






[awful]

[/awful]

You should be thinking Elementary my dear Watson seems CardLayout is not well used or perhap it can't be combined with the absolute layer of the JFrame

Well I agree, but I don't know where is the mistake

Thanks for any advice (I hope it won't take another ten years! internet is becoming old and wise)
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't set the layout manager of a JTabbedPane. Instead, create a new JPanel with that layout manager, and add your components to that.

However, it looks like you want to use two different techniques for doing the same thing - showing only one component (or set of components) at a time. The main difference between a JTabbedPane and a JPanel with a CardLayout is that the former has tabs. So why not just change the code to this:

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarcasm isn't really called for here.

JTabbedPane has its own layout manager; you can't set the layout manager of a JTabbedPane without breaking the whole thing. It especially doesn't make any sense to try to set the layout manager of a JTabbedPane to be a CardLayout, since both classes are attempting to accomplish more or less the same thing. You also aren't supposed to use the add() methods of JTabbedPane; rather, you have to use addTab().

When you're using a JTabbedPane properly, each tab contains a single component, typically a JPanel; you can, of course, set the layout manager for those -- and yes, you could use CardLayout, so that each tab contained a stack of cards.

This is all detailed in this page from the Java Tutorial.
 
Hernan Eche
Greenhorn
Posts: 6
C++ Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wasn't sarcasm, was a joke because your deduction surprised me, I am sorry if it seemed otherwise

The reason for using CardLayout is for making the "tab" dissapear, and it really works! (neglecting the exceptions saying the opposite)

I could use other component if it does animate the gif in the same way that JTabbedPane does

That's the reason I am doing that mixture.

Thanks again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!