0
Explorer
,
/t5/coldfusion-discussions/java-object-instantiation/td-p/864881
Jun 19, 2008
Jun 19, 2008
Copy link to clipboard
Copied
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")>
===================================================================================
TOPICS
Advanced techniques
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
1 Correct answer
Valorous Hero
,
Jun 19, 2008
Jun 19, 2008
You are instantiating the class correctly. It is a problem
with access modifiers. I do not know if you are familiar with java
modifiers, but cffunction has similar a concept
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001063.htm
Though the class itself is declared as "public"
public class StringEncryptWrapper {
...
}
Your constructor is not.
StringEncryptWrapper() {
...
}
I _think_ it is being assigned a default level of "package". Meaning you cannot instantiate it from ou...
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001063.htm
Though the class itself is declared as "public"
public class StringEncryptWrapper {
...
}
Your constructor is not.
StringEncryptWrapper() {
...
}
I _think_ it is being assigned a default level of "package". Meaning you cannot instantiate it from ou...
Valorous Hero
,
/t5/coldfusion-discussions/java-object-instantiation/m-p/864882#M79757
Jun 19, 2008
Jun 19, 2008
Copy link to clipboard
Copied
You are instantiating the class correctly. It is a problem
with access modifiers. I do not know if you are familiar with java
modifiers, but cffunction has similar a concept
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001063.htm
Though the class itself is declared as "public"
public class StringEncryptWrapper {
...
}
Your constructor is not.
StringEncryptWrapper() {
...
}
I _think_ it is being assigned a default level of "package". Meaning you cannot instantiate it from outside the package: com.adeptengr.EncryptDecrypt. That is why you are receiving the "Unable to find constructor.." exeception. It is not that CF cannot find the constructor, it just is not allowed to access it.
The solution is to explicitly declare the constructor _public_
public StringEncryptWrapper() {
...
}
http://livedocs.adobe.com/coldfusion/7/htmldocs/00001063.htm
Though the class itself is declared as "public"
public class StringEncryptWrapper {
...
}
Your constructor is not.
StringEncryptWrapper() {
...
}
I _think_ it is being assigned a default level of "package". Meaning you cannot instantiate it from outside the package: com.adeptengr.EncryptDecrypt. That is why you are receiving the "Unable to find constructor.." exeception. It is not that CF cannot find the constructor, it just is not allowed to access it.
The solution is to explicitly declare the constructor _public_
public StringEncryptWrapper() {
...
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
seyi103
AUTHOR
Explorer
,
LATEST
/t5/coldfusion-discussions/java-object-instantiation/m-p/864883#M79758
Jun 19, 2008
Jun 19, 2008
Copy link to clipboard
Copied
Thanks a bunch, worked like a charm after declaring the
constructor as public.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

