• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class cant be instanced,why?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please read the code followed
import java.applet.Applet;
import java.awt.*;
public class Sample extends Applet
{
private String text="hello World";
public void init ()
{
add(new Label(test));
}
public Sample(String str)
{
text=str;
}
}

when I appletviewer it ;
the out message is: Load Sample.class can't be instanced.
I cant find the quesion.
give me some comment about it.and If I want the code work.what
should i do?
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,
Applets expect to find a default constructor in the form:

The compiler creates this autmatically if no other constructor exits. Note: it doesn't have to be 'public', the compiler will create it using the same access modifier you used when declaring the class.
In your example, you supplied a ctor <code>Sample(String str)</code> so no default ctor was created. To get the applet to work either comment out the supplied ctor or add a default ctor.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
 
reply
    Bookmark Topic Watch Topic
  • New Topic