0

I am trying to compile serviceBean.java file which imports one of my package, ledgement.java

In the serviceBean.java I added the below one line and it is not compiled it throws Cannot Find Symbol

ledgement ack = new ledgement(false,
                        e);

Here is the folder structure:

C:\working\src\java\com\test\tools\abc\mgmt\facade\service    

com/test/tools/abc/mgmt/facade/service/serviceBean.java

com/test/tools/abc/mgmt/util/ledgement.java

My ledgement class contains

 public class ledgement<T> extends Test {

        public enum EntityType implements Serializable {
            ART(1), ART1(2), RDER(3), LNE(4), 
            COUNT(5);
            private int typeId;

            EntityType(int id) {
                this.typeId = id;
            }

            /**
             * @return the entityClass
             */
            public int getTypeId() {
                return typeId;
            }

            /**
             * @param entityClass
             *            the entityClass to set
             */
            public void setTypeId(int id) {
                this.typeId = id;
            }
        } // Enum EntityType.

    public ledgement(boolean successFg) {
            this(successFg , null, null, null, null);
        }
   public ledgement(boolean sucessFg, Exception exp) {
        this(sucessFg, exp, null);
    }

it throws cannot find symbol [javac] symbol : constructor ledgement(boolean,java.lang.Exception )

Not sure what is the issue by invoke the ledgment java class.
Please help.Thanks in Advance
3
  • Have you got import com.test.tools.abc.mgmt.util.ledgement in ServiceBean class? Commented Feb 28, 2019 at 9:20
  • Yes it is already imported Commented Feb 28, 2019 at 9:27
  • Is your e variable instantiated when you call it on the constructor? Commented Feb 28, 2019 at 9:40

2 Answers 2

1

you have an extra bracket in this line of code: this(successFg) , null, null, null, null);

Sign up to request clarification or add additional context in comments.

1 Comment

e is instantiated
0

Starting point

The "ledgement" class itself – without the nested enum – looks like this:

public class ledgement<T> extends Test {
    public ledgement(boolean successFg) {
        this(successFg, null, null, null, null);
    }

    public ledgement(boolean sucessFg, Exception exp) {
        this(sucessFg, exp, null);
    }
}

and here's an empty "Test" class so that things will compile:

class Test {
}

Your observation

You stated that by doing something like below:

new ledgement(false, e);

you see an error like this:

[javac] symbol : constructor ledgement(boolean,java.lang.Exception)

This error is not reproducible. Below is a slight edit to your code, newing an exception (instead of using "e" which wasn't defined in your posted code). This line compiles fine:

new ledgement(false, new Exception());

The problem

Both of the constructors in turn refer to another constructor which does not exist. This line:

this(successFg, null, null, null, null);

results in this compiler error:

no suitable constructor found for ledgement(boolean,<nulltype>,<nulltype>,<nulltype>,<nulltype>)
    constructor ledgement(boolean) is not applicable
      (actual and formal argument lists differ in length)
    constructor ledgement(boolean,java.lang.Exception) is not applicable
      (actual and formal argument lists differ in length)

And this line:

this(sucessFg, exp, null);

results in this compiler error:

no suitable constructor found for ledgement(boolean,java.lang.Exception,<nulltype>)
    constructor ledgement(boolean) is not applicable
      (actual and formal argument lists differ in length)
    constructor ledgement(boolean,java.lang.Exception) is not applicable
      (actual and formal argument lists differ in length)

Solution

Various things would probably help:

  • Pay close attention to the compiler errors.
  • Use declared constructors, matching the signatures – it's not allowed to call a constructor with several extra arguments (such as "null, null, null, null").
  • Use an IDE such as IntelliJ – it will surface problems like this for you.
  • If you're still seeing weird or strange things, do a clean build, remove previously compiled class files, etc. and try to reproduce the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.