Forum Stats

  • 3,852,836 Users
  • 2,264,140 Discussions
  • 7,905,157 Comments

Discussions

Problem with calling constructor from JNI code

843829
843829 Member Posts: 49,201
edited Sep 8, 2010 2:33PM in Java Native Interface (JNI)
I have no error when I am trying to call any method of the "Ursa_Routing_Output" object from the JNI code. But I am getting the same error when calling the constructor.

Problem with the Empty constructor
Exception in thread "Thread-23" java.lang.NoSuchMethodError: <init>
at com.comail.jni.UVSdk.getRPO(Native Method)

jclass jRpo=env->FindClass("com/comail/pojo/Ursa_Routing_Output");
  	if(jRpo==NULL)
  	{
  	 printf("Class can't be found \n");
  	 return NULL;
  	}


	jmethodID test=env->GetMethodID(jRpo,"getAreaCommitment","()Ljava/lang/String;");
	if(test==NULL)
  	{
  	printf("\nProblem with the Test Method \n");
	return NULL;
 	}
	
    jmethodID uroEmptyConst  = env->GetMethodID(jRpo,"<init>","()v");
	if(uroEmptyConst==NULL)
  	{
  	printf("\nProblem with the Empty constructor \n");
	return NULL;
 	}
The corresponding methods in the Java class are :
public class Ursa_Routing_Output implements Serializable {

	/**
	 *   Class fields 
	 */

       public Ursa_Routing_Output() {
		super();
		// TODO Auto-generated constructor stub
	}

   ...........
............

     public String getAreaCommitment() {
		return AreaCommitment;
	}
The corresponding class signatures generated through javap are :

public com.comail.pojo.Ursa_Routing_Output();
Signature: ()V

public java.lang.String getAreaCommitment();
Signature: ()Ljava/lang/String;


The code is able to find the class and its other methods. But it is not able to locate the constructor.

Can any one help me to locate the problem?

Comments

  • jschellSomeoneStoleMyAlias
    jschellSomeoneStoleMyAlias Member Posts: 24,877 Gold Badge
    Why are you not using NewObject()?
    ...","()v");
    Upper case V.
  • 843829
    843829 Member Posts: 49,201
    ThankYou jschell.. Just figured it out !!

    I do have another issue in the same class for the parameterized constructor ... As that is similar I will post it here only ..
    public Ursa_Routing_Output(String postalCode, String cleanedPostal,
    			String country, String location, String finalLocation,
    			String labelLocation, String rampID, String state,
    			String locationState, String postalState, String areaCommitment,
    			String cityList, String hold, String prefix, String labelPrefix,
    			String deliveryDate, int deliveryDay, String trueCommitDate,
    			int trueCommitDay, int ursaStatus, long softError, int error,
    			String svc, String pkg, String barcode3String,
    			String barcodeString, int barcodeType, int julianDay,
    			int forceBarcodeByDestLoc, String astraVersion, String versionNumber) { .......... }
    Signature generated from javap :
    (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;IIJILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIILjava/lang/String;Ljava/lang/String;)V
    I have just copy pasted the signature into this GetMethodID function :
    jmethodID uroConst  = env->GetMethodID(jRpo,"<init>","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;IIJILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIILjava/lang/String;Ljava/lang/String;)V");
    
    /* Copy pasting the same signature here to check for the match 
    ......................................................................................................................................(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;IIJILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIILjava/lang/String;Ljava/lang/String;)V
    */
    
    if(uroConst==NULL)
      	{
      	printf("\nProblem with the constructor \n");
    	return NULL;
     	}
    But I am getting the error :

    Problem with the constructor
    Exception in thread "Thread-23" java.lang.NoSuchMethodError: <init>
This discussion has been closed.