Answered
Java Object Instantiation
I'm having problems using a method within a java class that
has been created within my CF code. I don't know Java, but from the
little I've learnt the Java code has a constructor. When I call the
method within the java class without using the CF init() it throws
an Object Instantiation Exception as below:
===================================================================================
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor explicitly using the init(args) method. Error : Class coldfusion.runtime.java.JavaProxy can not access a member of class com.adeptengr.EncryptDecrypt.StringEncryptWrapper with modifiers
===================================================================================
however when I do use the init() it throws the following error:
===================================================================================
Unable to find a constructor for class com.adeptengr.EncryptDecrypt.StringEncryptWrapper that accepts parameters of type ( '' ).
===================================================================================
As seen in the java code below, the default constructor doesn't accept any argument, and the method that needs to be called in the encrypt method. Please is there anyone who can help or point me in the right direction? Thanks
Java Code:
===================================================================================
public class StringEncryptWrapper
{
StringEncryptWrapper()
{
try
{
myEncrypter = new StringEncrypter("DES");
}
catch(StringEncrypter.EncryptionException e)
{
e.printStackTrace();
}
}
public String encrypt(String stringToBeEncrypted)
throws StringEncrypter.EncryptionException
{
return myEncrypter.encrypt(stringToBeEncrypted);
}
public String decrypt(String stringToBeDecrypted)
throws StringEncrypter.EncryptionException
{
return myEncrypter.decrypt(stringToBeDecrypted);
}
StringEncrypter myEncrypter;
}
===================================================================================
CF code:
===================================================================================
<cfobject type="Java" action="create" class="com.adeptengr.EncryptDecrypt.StringEncryptWrapper" name="encrypter">
<cfset encrypter.init()>
<cfset encrypted = encrypter.encrypt("adepttest")>
===================================================================================
===================================================================================
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor explicitly using the init(args) method. Error : Class coldfusion.runtime.java.JavaProxy can not access a member of class com.adeptengr.EncryptDecrypt.StringEncryptWrapper with modifiers
===================================================================================
however when I do use the init() it throws the following error:
===================================================================================
Unable to find a constructor for class com.adeptengr.EncryptDecrypt.StringEncryptWrapper that accepts parameters of type ( '' ).
===================================================================================
As seen in the java code below, the default constructor doesn't accept any argument, and the method that needs to be called in the encrypt method. Please is there anyone who can help or point me in the right direction? Thanks
Java Code:
===================================================================================
public class StringEncryptWrapper
{
StringEncryptWrapper()
{
try
{
myEncrypter = new StringEncrypter("DES");
}
catch(StringEncrypter.EncryptionException e)
{
e.printStackTrace();
}
}
public String encrypt(String stringToBeEncrypted)
throws StringEncrypter.EncryptionException
{
return myEncrypter.encrypt(stringToBeEncrypted);
}
public String decrypt(String stringToBeDecrypted)
throws StringEncrypter.EncryptionException
{
return myEncrypter.decrypt(stringToBeDecrypted);
}
StringEncrypter myEncrypter;
}
===================================================================================
CF code:
===================================================================================
<cfobject type="Java" action="create" class="com.adeptengr.EncryptDecrypt.StringEncryptWrapper" name="encrypter">
<cfset encrypter.init()>
<cfset encrypted = encrypter.encrypt("adepttest")>
===================================================================================
