Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

getApplet() throws incompatible type error ?

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I've implemented a class TXRecord which collects transient record data from client applets using a Hashtable. To achieve this, my client applets tries to get a handle on TXRecord in order to use its method to insert a record.
However the client applet is throwing a compile time error

incompatible types
found : java.applet.Applet
required: javax.swing.Applet
.......{ JApplet app_txrecord = JApplet.getAppletContext().getApplet("TXRecord");

Here is the TXRecord class which it objects to...

And here is the code snippet which tries to get a handle on TXRecord

Where have I gone wrong here, can anyone helpout please!
TIA :-)
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Achana
In the line,
JApplet app_txrecord = ...
Try to replace JApplet with Applet OR
cast the right hand side with (javax.swing.JApplet)
because getApplet() will return java.awt.Applet object and on left hand side you have app_txrecord as JApplet.
Thanks
Maulin
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Thanks for replying.
I've tried casting it as JApplet and leaving it as Applet, like this:

All of them throws the same compile time error msg;

cannot resolve symbol
method getAppletContext()
Applet app_txrecord = (Applet)getAppletContext().getApplet("TXRecord");

TIA :-)
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Achana
I see that you removed JApplet.getAppletContext() and instead just using getAppletContext() directly ...may be its just while editing you ended up removing it..
Put it back in addition to the casting you are doing and see it works...
Regards
Maulin
 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for replying.
I've tried out all these combinations, they all return the same compile time error, namely "cannot resolve symbol, method getAppletContext()"

TIA :-)
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your ClientApplet needs to extend JApplet I think
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic