[java] Two constructors

As I remember I can use first constuctor in second constuctor, but there is mistake on bold line, could you help me to correct it?

  public FaceExtAdditionCanvas() {     profileImage.setSize(IMAGE_WIDTH, IMAGE_HEIGHT);     add(profileImage, getWidth() / 2.0 - IMAGE_WIDTH / 2.0, IMAGE_MARGIN);   }    public FaceExtAdditionCanvas(GImage image){     profileImage=image;     **this.FaceExtAdditionCanvas();**   } 

This question is related to java constructor

The answer is

To call one constructor from another you need to use this() and you need to put it first. In your case the default constructor needs to call the one which takes an argument, not the other ways around.

The first line of a constructor is always an invocation to another constructor. You can choose between calling a constructor from the same class with "this(...)" or a constructor from the parent clas with "super(...)". If you don't include either, the compiler includes this line for you: super();

Questions with java tag:

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error Instantiating a generic type When to create variables (memory management) java doesn't run if structure inside of onclick listener String method cannot be found in a main class method Are all Spring Framework Java Configuration injection examples buggy? Calling another method java GUI I need to know how to get my program to output the word i typed in and also the new rearranged word using a 2D array Java and unlimited decimal places? Read input from a JOptionPane.showInputDialog box Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable Two Page Login with Spring Security 3.2.x Hadoop MapReduce: Strange Result when Storing Previous Value in Memory in a Reduce Class (Java) Got a NumberFormatException while trying to parse a text file for objects Best way for storing Java application name and version properties Call japplet from jframe FragmentActivity to Fragment Comparing two joda DateTime instances Maven dependencies are failing with a 501 error IntelliJ: Error:java: error: release version 5 not supported Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Why am I getting Unknown error in line 1 of pom.xml? Gradle: Could not determine java version from '11.0.2' Error: Java: invalid target release: 11 - IntelliJ IDEA Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Why is 2 * (i * i) faster than 2 * i * i in Java? must declare a named package eclipse because this compilation unit is associated to the named module How do I install Java on Mac OSX allowing version switching? How to install JDK 11 under Ubuntu? Java 11 package javax.xml.bind does not exist IntelliJ can't recognize JavaFX 11 with OpenJDK 11 Difference between OpenJDK and Adoptium/AdoptOpenJDK OpenJDK8 for windows How to allow all Network connection types HTTP and HTTPS in Android (9) Pie? Find the smallest positive integer that does not occur in a given sequence Error: JavaFX runtime components are missing, and are required to run this application with JDK 11 How to uninstall Eclipse? Failed to resolve: com.google.firebase:firebase-core:16.0.1 How to resolve Unable to load authentication plugin 'caching_sha2_password' issue

Questions with constructor tag:

Two constructors Class constructor type in typescript? ReactJS: Warning: setState(...): Cannot update during an existing state transition Inheritance with base class constructor with parameters What is the difference between using constructor vs getInitialState in React / React Native? Getting error: ISO C++ forbids declaration of with no type undefined reference to 'vtable for class' constructor Call asynchronous method in constructor? Purpose of a constructor in Java? __init__() missing 1 required positional argument How to call Base Class's __init__ method from the child class? C# : assign data to properties via constructor vs. instantiating Methods vs Constructors in Java Constructors in Go Pass arguments to Constructor in VBA best way to create object Hide Utility Class Constructor : Utility classes should not have a public or default constructor How can I initialize C++ object member variables in the constructor? Constructor overload in TypeScript Creating an instance of class Calling the base class constructor from the derived class constructor Javascript "Not a Constructor" Exception while creating objects PHP constructor with a parameter expected constructor, destructor, or type conversion before ‘(’ token How do I declare an array with a custom class? Serialize JavaScript object into JSON string Can constructors be async? Using C++ base class constructors? Java constructor/method with optional parameters? C# Error: Parent does not contain a constructor that takes 0 arguments How do I call the base class constructor? C++: Where to initialize variables in constructor How to force deletion of a python object? Is there a way to @Autowire a bean that requires constructor arguments? C# static class constructor Creating an object: with or without `new` Is it good practice to make the constructor throw an exception? Constructor of an abstract class in C# C# constructors overloading Java. Implicit super constructor Employee() is undefined. Must explicitly invoke another constructor Can I call methods in constructor in Java? Is Constructor Overriding Possible? no default constructor exists for class Python constructor and default value Object array initialization without default constructor What is the use of static constructors? Java default constructor Call one constructor from another C++ template constructor Code snippet or shortcut to create a constructor in Visual Studio