Default Constructor Help?

class A {
public A() {
public A(int) {
//--main method--
}This is an assignment that I'm having some trouble with So let's say I have class A and the default constructor, as well as a constructor that takes an int. The default A constructor is supposed to have an object created by a call to the default constructor of objects, java.lang.Object. However, if I try to refer to the default Object() constructor by using super();, it creates a NullPointerException error (obviously). So is there some sort of default object or something that I'm supposed to use?
Thanks for all the help :)

I mean it generates the error during runtime; i can compile it okay.Sorry, I missed that you said it was a NullPointerException.
For example, it seems to generate the error on the line A.getClass(); even though I don't think it should.That line isn't in the code you posted. The same thing applies really: post a brief example that gives the runtime error along with the exact stack trace that is produced.

Similar Messages

  • ORA-02315: incorrect number of arguments for default constructor

    I was able to register the XML schema successfully by letting Oracle creating the XML Types. Then when I try to execute the create view command the ORA-02315: incorrect number of arguments for default constructor is always raised.
    I tried using the XMLTYPE.createXML but it gives me the same error.
    Command:
    CREATE OR REPLACE VIEW samples_xml OF XMLTYPE
    XMLSCHEMA "http://localhost/samplepeak4.xsd" ELEMENT "SAMPLE"
    WITH OBJECT ID (ExtractValue(sys_nc_rowinfo$, '/SAMPLES/SAMPLE/SAMPLE_ID')) AS
    SELECT sample_t(s.sample_id, s.patient_info, s.process_info, s.lims_sample_id,
    cast (multiset(
    SELECT peak_t(p.peak_id, p.mass_charge, p.intensity, p.retention_time,
    p.cleavage_type, p.search_id, p.match_id, p.mass_observed,
    p.mass_expected, p.delta, p.miss, p.rank, p.mass_calculated,
    p.fraction)
    FROM peak p
    WHERE s.sample_id = p.sample_id) AS PEAK107_COLL))
    FROM sample s;
    Can someone help me.
    Thanks
    Carl

    This example runs without any problems on 9.2.0.4.0. Which version are you running? And which statement causes the error message?

  • No appropriate default constructor c++

    Hi, have been trying to read up on it but I need some help to understand it, here's my code. What should I do to make it work and how should I try to think about it in the future?
    cheers
    Law.h
    #include <iostream>
    #include <string>
    using namespace std;
    class Law
    private:
    int k;
    int x;
    int F;
    int m;
    const int g;
    void init();
    public:
    void Introduce();
    int getMass();
    int getLenght();
    Law.ccp
    #include "Law.h"
    int Law::getMass()
    return m;
    int Law::getLenght()
    return x;
    void Law::Introduce()
    cout << "\nWelcome to a very simplified Hooke's Law Calculator" << endl;
    cout << "\nplease type in your mass: ";
    main.ccp
    #include <iostream>
    #include <string>
    #include "Law.h"
    using namespace std;
    int main()
    Law hLaw;
    hLaw.Introduce();
    system("pause");
    return 0;

    On 1/11/2015 8:50 AM, RonnerBBQ wrote:
    class Law
    private:
    const int g;
    Law hLaw;
    The variable hLaw needs to be initialized - with a default constructor in this case. Class  Law doesn't have any user-defined constructors. Normally, a compiler would implicitly define a default constructor, equivalent to Law::Law() {} . But in
    this case, it can't - Law has a const data member, which must be initialized in constructor (it being const, there won't be any other chance), and the compiler doesn't know what value to initialize it to.
    You can 1) explicitly define a default constructor, and initialize g there, or 2) drop "const" from g (or drop g entirely, seeing as you aren't using it), or 3) give g an initializer, as in "const int g = 42;"
    Igor Tandetnik

  • Dynamic classloading without default constructor

    Just wondering if anyone has done dynamic classloading using a constructor other than the default. I know that newInstance() calls the default constructor. But how would you do it without that? Thanks for the help.

    If you know that there is a constructor that takes,
    for example, a single String argument you can use
    something like this:
    Class clazz = ...; // class to instantiate
    String stringArg = ...; // argument to pass to constructor
    Constructor c = clazz.getConstructor( new Class[] { String.class } );
    Object value = c.newInstance( new Object[] { stringArg > } );
    And even better, when JDK 1.5 is released, you'll be able to write:
        Class clazz = ...;
        String stringArg = ...;
        Constructor c = clazz.getConstructor(String.class);
        Object value = c.newInstance(stringArg);Geoff

  • De-serialization not calling default constructor ??

    Hi,
    I have a strange problem with serialization (de-serialization, actually):
    I have a bunch of classes that represent the model for my application.
    These classes are organized as a complex tree and come in three flavors:
    public abstract class AbstractIOCLeaf implements IOCElement {
         private String name;
         private transient boolean changed = false;
         private transient LinkedList<ChangeListener> changeListeners;
         protected AbstractIOCLeaf() {
              super();
              name = null;
              changed = false;
              changeListeners = new LinkedList<ChangeListener>();
         } //needed for Serialzation
         protected AbstractIOCLeaf(String name) {
              this();
              this.name = name;
    ...this class is a leaf: it cannot contain other sub-elements.
    public abstract class AbstractIOCList<T extends IOCElement> extends AbstractIOCNode implements ComboBoxModel {
         protected LinkedList<T> list = null;
         protected transient List<ListDataListener> listListeners;
         protected abstract T newElement(String name);     
         protected AbstractIOCList() { super();  listListeners = new LinkedList<ListDataListener>(); }
         public AbstractIOCList(String name) {
              super(name);
              list = new LinkedList<T>();
              listListeners = new LinkedList<ListDataListener>();
    ... This class holds a list of elements that are all equal.
    and finally:
    public abstract class AbstractIOCNode extends AbstractIOCLeaf implements ChangeListener, ListDataListener {
         protected AbstractIOCNode() { super(); }
         protected AbstractIOCNode(String name) {
              super(name);
    ... This class holds elements that are all different.
    The actual classes extends one of these following the pattern:
    public class StateMachine extends AbstractIOCNode {
         private StateList states = null;;
         private EventQueue fEventQueue = null;
         private StateMachine() { super(); }
         private StateMachine(String name) {
              super(name);
              states = StateList.newInstance(this);
              changed = false;
         public static StateMachine newInstance(String name) {
              StateMachine sm = new StateMachine(name);
              sm.initialize();
              return sm;
    public class StateList extends AbstractIOCList<State> {
         private StateMachine sm;
         private StateList() { super("StateList"); sm = null; }
         private StateList(StateMachine sm) {
              this();
              this.sm = sm;
         public static StateList newInstance(StateMachine sm) {
              StateList list = new StateList(sm);
              list.initialize();
              return list;
    ...etc. etc.
    I do serialization calling ObjectOutputStream.writeObject on the root object and (obviously) deserialize using ObjectOutputStream.readObject.
    The process works, but it seems that the default constructors in particular AbstractIOCLeaf() is never called while deserializing. First hint to something amiss was the fact that I always had the transient field changeListeners remaining in its default null state.
    Further investigation involving debugging and breakpointing confirmed no default constructor is called in spite of the super(); calls.
    What am I doing wrong??
    Did I miss something about serialization (apparently so, but I cannot understand what!)?
    Side issue:
    I tried substituting ObjectOutputStream.writeObject with XMLEncoder.writeObject, but then I get the error: "Class sun.reflect.misc.Trampoline can not access a member of class com.softin.IOCbuilder.model.IOController with modifiers "private"".
    Aren't those classes supposed to be equivalent?
    Is there any (fast) way to desume the offending member?
    Excuse me for the length of the post and
    Thanks in Advance
    Mauro

    Oops, nevermind. Sorry.

  • Creating an instance of a class with no default constructor

    Hello gurus,
    I wrote my own serialization and RMI protocol for both C++ and Java that follows closely what the default Java version does. I'm trying to recreate an object on the Java side that was sent over the wire. The first step is to create an instance of the class. How do I create an instance of a class that has no constructor (i.e. the only instances are static, created by the class itself and returned by static methods) or one that has no default constructor (like Integer)? The Java serialization seems to support it but the reflection API doesn't seem to have any support for this (i.e. Class::newInstance() and Constructor::newInstance()). It seems that through the standard API you can only create an object via one of its constructors. There must be a "hidden" method somewhere that allows the Java serialization to create an object without calling a constructor - where is it?
    Dominique

    There must be a "hidden" method
    somewhere that allows the Java serialization to create
    an object without calling a constructor - where is
    it?You are correct, the way in which the Serialization creates Objects is "hidden" deep within the runtime.
    If it were not hidden, you would be able to find it, and use it to violate the integrity of the VM.

  • Selective member import/export using dllexport and default constructor

    We can only export some methods in the class(https://msdn.microsoft.com/es-es/library/8d7d1303-b9e9-47ca-96cc-67bf444a08a9%28v=vs.100%29)
    What if we export only some methods in the class and not exported the default constructor(Will it get generated by the compiler in external app which use this dll?).The class may have some private data member as well which are not exposed in the published
    header file(Which we distribute with DLL).
    How the memory gets allocated to those private data members which are not exposed as the default constructor is not exported? 
    Niranjan

    We can only export some methods in the class(https://msdn.microsoft.com/es-es/library/8d7d1303-b9e9-47ca-96cc-67bf444a08a9%28v=vs.100%29)
    What if we export only some methods in the class and not exported the default constructor(Will it get generated by the compiler in external app which use this dll?).The class may have some private data member as well which are not exposed in the published
    header file(Which we distribute with DLL).
    How the memory gets allocated to those private data members which are not exposed as the default constructor is not exported? 
    Niranjan

  • Failing with 'no-arg default constructor' on @XmlTransient

    Hello,
    I have a simple exception I want to serialize to xml like this:
    public class Main {
    @XmlRootElement
    static public class SomeException extends RuntimeException {
    private Integer someAdditionalInformation;
    public SomeException() {
    public SomeException(Integer someAdditionalInformation) {
    this.someAdditionalInformation = someAdditionalInformation;
    public Integer getSomeAdditionalInformation() {
    return someAdditionalInformation;
    public void setSomeAdditionalInformation(
    Integer someAdditionalInformation) {
    this.someAdditionalInformation = someAdditionalInformation;
    @XmlTransient
    @Override
    public StackTraceElement[] getStackTrace() {
    return super.getStackTrace();
    public static void main(String[] args) {
    try {
    JAXBContext jaxbCtx = JAXBContext.newInstance(SomeException.class);
    Marshaller m = jaxbCtx.createMarshaller();
    m.marshal(new SomeException(5), System.out);
    } catch (JAXBException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    But I get the following exception:
    com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
    java.lang.StackTraceElement does not have a no-arg default constructor.
    this problem is related to the following location:
    at java.lang.StackTraceElement
    at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
    at java.lang.Throwable
    at java.lang.Exception
    at java.lang.RuntimeException
    at jaxbtest.Main$SomeException
    Does this seam like a JAXB bug ?
    @XmlTransient should make JAXB just skip that property.
    Is there ant way to workaround this ?
    PS. Where did the JAXB team fly away ? jaxb.dev.java.net is blank

    Looking at your log it is clear that, you are populating Xellerate Type=null. This is mandatory field and can't be null. However, when you create user using UI, the default value "End-Users" is being passed by default, because we have the corresponding field "Design Console" access check box at oim user profile.
    Just map the constant value for trusted recon
    Xellerate Type=End-Users
    --nayan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Super class default constructor

    Hello,
    I want to clear some confusion. I am studying for the exam. In this particular book an example shows that
    Super class has 2 constructor
    public abc() and public abc(int n)
    Sub class has 2 constructor
    public xyz() and public xyz(int n)
    now when an instance is created for the subclass
    xyz t = new xyz(1)
    It will invoke the super class no argument constructor eventhough a default constructor exist in subclass?
    Regards,
    adil

    Here are the rules for constructors--"ctors" because I'm lazy. Also, because I'm lazy, "super(...)" and "this(...)" mean any super or this call, regardless of how many args it takes, including those that take no args.
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • What is the need for calling default constructor by JVM?

    What is the need for calling default constructor by JVM? why the JVM should intiializes default values to the data
    fields if the constructor is not there in our class?

    mahar wrote:
    What is the need for calling default constructor by JVM? Huh? The JVM does not need to call the default constructor. It needs to call a constructor.
    You decide which one by the way you use "new".
    why the JVM should initialize default values to the data fieldsHuh?
    ... if the constructor is not there in our class?Huh? The default constructor is always there. It may be private but it is still there.

  • Will 1.5 compiler tag default constructor as synthetic?

    Hi,
    This is a question about the synthetic attribute for the default constructor. This attribute has been added at the moment the inner classes have been introduced in the language. I think its purpose is to distinguish methods added by the compiler (like the access methods) to handle the inner classes.
    Synthetic basically means something that has been added by the compiler and that has no corresponding source code.
    Following this, the default constructor (added when the class has no constructor) should also be tagged with a synthetic attribute, shouldn't it?
    Javac 1.4.2 doesn't add this attribute for the default constructor and I was wondering if the version 1.5 would do it.
    Thanks,
    Olivier

    As far as I tested the jdk 1.5 compiler, I found that
    it already tags default constructors with isSynthetic
    attribute. Default constructors are compiler generated
    and I am not sure how it affects the api, if they are
    tagged isSynthetic.No, the 1.50 beta 31 compiler does not tag default constructors with Synthetic attributes.

  • Has anyone experience this! - default browser helper 537

    Hi,
    I use Firefox as my default browser, since the firefox plug-in "default browser helper 537" was installed (in November) my mac has slow down, especially when browsing using both firefox and safari. I un-installed firefox a week ago and my pc has gone back to it original state. I installed Firefox again after two days from the previous un-install and the browsing slow down again. I then un-installed again. Has anyone experience this! IS there a issue with Firefox???

    Just experienced same today. Firefox didn't even want to quit without a force quit. Removed Firefox and so far so good with other browsers - Safari and Chrome

  • Edit Default Serach help

    HI Experts,
                   Is there any way to personalize the settings available on search help?
    Default serach help comming for my input field contains two fields. i want to hide one with my code.
    Please suggest if u have some idea to do this
    Regards
    Sarath

    Hi,
    Its not possible .... u have to copy that search help as Z search help and then disable that field for display ...
    regards
    Yash

  • Create POJO instance in fxml with no default constructor

    My question is that how to create POJO instance in fxml that has no default constructor. I am creating pie chart data object in fxml like this
    *<fx:define>*
    *<PieChart.Data fx:id="data" >*
    *<name>java</name>*
    *<pieValue>20.2</pieValue>*
    *</PieChart.Data>*
    *</fx:define>*
    since there is no default constructor how to create this object fxml?
    Edited by: 988476 on Feb 16, 2013 6:21 AM

    There must be a "hidden" method
    somewhere that allows the Java serialization to create
    an object without calling a constructor - where is
    it?You are correct, the way in which the Serialization creates Objects is "hidden" deep within the runtime.
    If it were not hidden, you would be able to find it, and use it to violate the integrity of the VM.

  • Always create any Object even without default constructor?

    hi!
    i'm wondering if there's an easy way to construct an object of a given class?
    let's assume i've got a class
    class MyClass
         public MyClass( OtherClass c)
    }now when i get the constructors for its Class-object with
    clazz.getDeclaredConstructor()
    it will return null;
    ok now i know ther's no default/empty constructor.
    does it make sense to then search for the next constructor with n parameters?
    and then invoke it with nonsense values?
    what happens if the parameter classes also have no default constructor to create parameter objects? like this:
    class OtherClass
         public OtherClass ( MyClass c)
    }now there's a loop between the two constructors and i can't create empty parameter values to invoke any of them!
    i wonder how the serialization engine works then?
    or did i miss something trivial (it's really late here ;) )

    What's the problem? To create a MyClass object, you
    don't need any OtherClass objects. You just do the
    equivalent ofnew MyClass(null)in your
    reflective code.
    slap forehead with toilet
    thanks for the tip.
    as i said there was something absolutely easy, it's tough not seeing the forest for the trees ;/
    But I agree with jschell, if your requirements are to
    create objects of arbitrary classes and call
    arbitrary methods with arbitrary parameter lists,
    then whoever did your design didn't think for long
    enough.WELL. you're absolutely right. but when it's time to process ANY given object there's no reliability on whatever design was chosen. or, would you insist the developer had to provide standatized formats when you write a debugger? no it has to work with any. so must i!

Maybe you are looking for

  • Installing Yosemite from 10.6.8 - Now stuck in OSX Installer

    I have a White Macbook that was running Snow Leopard and I figured I would try to install Yosemite onto it because why not. Downloading was fine, installing seemed fine, but after the "22 minutes remaining" screen, the bar at the bottom doesn't move

  • Tab canvas on a content Canvas

    Hi, I need to put a tab canvas on a content canvas in 10g R2. and have items from the same data block distributed across the canvases. I have set them up with the appropriate viewport for the tab canvas, but at runtime, the tab canvas does not appear

  • Will there ever be an update for retina display on InDesign CS6?

    I know I'm a little late in the game guys...Didn't know all the details of this retina display business, but I figured it was the way of the future and I should just bite the bullet and get one. I've read everything I could find about InDesign and re

  • Program to compare versions

    Hi! Theer is some migration work goin on from 4.7 to ECC 5.0 version. Can anybody tell me some sap standard program or Z-program. which compares the versions of no. of programs between different clients in single run. Thanks in Advance, Harkamal

  • Safari randomly quits

    I have only had a Mac for a few weeks now but the last week or so Safari (mostly but one time either word or entourage can't remember which also) randomly closes and asks me if I want to reopen it. It seems to reopen without issue. Is there some way