Maxtech
Maxtech

Reputation: 111

calling Generic class in Bean class method gives error

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

Upvotes: 0

Views: 63

Answers (2)

Kaan
Kaan

Reputation: 5754

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.

Upvotes: 0

dsokol
dsokol

Reputation: 11

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

Upvotes: 1

Related Questions