title: java.lang.NoSuchFieldError error in java
body: <p>I am creating a java application which uses JNI. One of the JNI function accept enum as parameter. But after the JNI uses the parameter java displays java.lang.NoSuchFieldError. </p>
  
  <p>Here's the java code:</p>
  
  <pre><code>private int convert(JacsbclibLoader.BCTemplateEnvelopeType inputTemplateEnvelopeType,      JacsbclibLoader.BCTemplateDataType inputTemplateDataType, JacsbclibLoader.BCTemplateEnvelopeType outputTemplateEnvelopeType, JacsbclibLoader.BCTemplateDataType outputTemplateDataType, byte[] inputData, byte[] outputData, JacsbclibLoader.BCTemplateInfoType_1 suplementaryInfo)
  {
  
      if(outputData != null)
          outputLength = outputData.length;
  
      status = _bclib.jBCConvertTemplate(inputTemplateEnvelopeType, inputTemplateDataType,inputData, inputData.length, outputTemplateEnvelopeType,                                    outputTemplateDataType, outputData, outputLength, suplementaryInfo);
      return status;
  }
  </code></pre>
  
  <p>Here's the Native code in java:</p>
  
  <pre><code>public enum BCTemplateDataType
  {
      BCT_NOT_SPECIFIED(-1),
      BCT_NONE(0),
      BCT_UPEK_LEGACY(1),
      BCT_UPEK_ALPHA(2),
      BCT_UPEK_BETA(3),
      BCT_UPEK_AUTO(4),
      BCT_ANSI(5),
      BCT_ISO_FMR(6),
      BCT_ISO_FMC_NORMAL(7),
      BCT_ISO_FMC_COMPACT(8),
      BCT_ABAPI(9),
      BCT_LAST(10);
  
      private int value;
  
      private BCTemplateDataType(int value)
      {
          this.value = value;
      }   
  }
  
  public int jBCConvertTemplate(BCTemplateEnvelopeType inputEnvelopeType,
                                    BCTemplateDataType inputDataType,
                                    byte[] inputData,
                                    int inputDataLength,
                                    BCTemplateEnvelopeType outputEnvelopeType,
                                    BCTemplateDataType outputDataType,
                                    byte[] outputData,
                                    int outputDataLength,
                                    BCTemplateInfoType_1 suplementaryInfo)
      {
          ret = BCConvertTemplate(inputEnvelopeType, inputDataType, inputData, inputDataLength, outputEnvelopeType, outputDataType, outputData, outputDataLength, suplementaryInfo);
          return ret;
      };
  
      private native int BCConvertTemplate(BCTemplateEnvelopeType inputEnvelope,
                                           BCTemplateDataType inputDataType,
                                           byte[] input,
                                           int inputLength,
                                           BCTemplateEnvelopeType outputEnvelope,
                                           BCTemplateDataType outputDataType,
                                           byte[] output,
                                           int outputLength,
                                           BCTemplateInfoType_1 suplementaryInfo);
  </code></pre>
  
  <p>Here's the JNI code in C++:</p>
  
  <pre><code>    JNIEXPORT jint JNICALL Java_JacsbclibLoader_BCConvertTemplate
    (JNIEnv *env, jobject obj, jobject inputEnvelope, jobject inputDataType, jbyteArray inputData, jint inputLength, jobject outputEnvelope, jobject outputDataType, jbyteArray outputData, jint outputLength, jobject suplementaryInfo)
  {
      LoadLib();
  
  
      BCTemplateInfoType_1 supInfo;
  
  
      BCTemplateEnvelopeType eInputTemplateEnvelopeType = BCTE_NONE;
      BCTemplateEnvelopeType eOutputTemplateEnvelopeType = BCTE_NONE;
  
      BCTemplateDataType eInputTemplateDataType = BCT_NONE;
      BCTemplateDataType eOutputTemplateDataType = BCT_NONE;
  
  
      jbyte *inputTemplate = env-&gt;GetByteArrayElements(inputData, 0);
      jbyte *outputTemplate = NULL;
  
      if(outputData != NULL)
      {
          MessageBox(NULL,"outputData != NULL","",0);
          jbyte *outputTemplate = env-&gt;GetByteArrayElements(outputData, 0);
      }
  
  
  
      jclass cls = env-&gt;GetObjectClass(obj);
      jfieldID fIdInputLength = env-&gt;GetStaticFieldID(cls, "inputLength", "I");
      jfieldID fIdOutputLength = env-&gt;GetStaticFieldID(cls, "outputLength", "I");
  
  
      if(pConvertTemplate)
      {
  
  
          /*int inputEnvelopeType;
          int inputEnvelopeDataType;
          int outputEnvelopeType;
          int outputEnvelopeDataType;*/
  
          /*jclass envelopeTypeClass = env-&gt;FindClass("JacsbclibLoader");
          MessageBox(NULL,"3.1","",0);
          jmethodID inputEnvelopeGetValueMethod = env-&gt;GetMethodID(envelopeTypeClass, "getValue", "I()");
          MessageBox(NULL,"3.2","",0);
          jint inputEnvelopeValue = env-&gt;CallIntMethod(inputEnvelope, inputEnvelopeGetValueMethod);
  
          MessageBox(NULL,"3.3","",0);
          eInputTemplateEnvelopeType = (BCTemplateEnvelopeType)inputEnvelopeValue;
          MessageBox(NULL,"3.4","",0);*/
  
          jclass inputEnvelopeClass = env-&gt;GetObjectClass(inputEnvelope);
          jclass inputEnvelopeDataTypeClass = env-&gt;GetObjectClass(inputDataType);
          jclass outputEnvelopeClass = env-&gt;GetObjectClass(outputEnvelope);
          jclass outputEnvelopeDataTypeClass = env-&gt;GetObjectClass(outputDataType);
  
          if(suplementaryInfo != NULL)
          {
              MessageBox(NULL,"4","",0);
  
              int ver;
              int captureCbeffpId;
              int captureEquiptCompliance;
              int captureEquiptId;
              int imgWidth;
              int imgHeight;
              int imgHorizontalResolution;
              int imgVerticalResolution;
              int fingerPos;
  
              jclass suplementaryClass = env-&gt;GetObjectClass(suplementaryInfo);
  
              jfieldID fIdVersion = env-&gt;GetFieldID(suplementaryClass, "version", "I");
              jfieldID fIdCaptureCbeffpid = env-&gt;GetFieldID(suplementaryClass, "captureCBEFFPid", "I");
              jfieldID fIdCaptureEquipmentCompliance = env-&gt;GetFieldID(suplementaryClass, "captureEquipmentCompliance", "I");
              jfieldID fIdCaptureEquipmentId = env-&gt;GetFieldID(suplementaryClass, "captureEquipmentId", "I");
              jfieldID fIdImageWidth = env-&gt;GetFieldID(suplementaryClass, "imageWidth", "I");
              jfieldID fIdImageHeigth = env-&gt;GetFieldID(suplementaryClass, "imageHeight", "I");
              jfieldID fIdImageHorizontalResolution = env-&gt;GetFieldID(suplementaryClass, "imageHorizontalResolution", "I");
              jfieldID fIdImageVerticalResolution = env-&gt;GetFieldID(suplementaryClass, "imageVerticalResolution", "I");
              jfieldID fIdFingerPosition = env-&gt;GetFieldID(suplementaryClass, "fingerPosition", "I");
  
              ver = env-&gt;GetIntField(suplementaryInfo, fIdVersion);
              captureCbeffpId = env-&gt;GetIntField(suplementaryInfo, fIdCaptureCbeffpid);
              captureEquiptCompliance = env-&gt;GetIntField(suplementaryInfo, fIdCaptureEquipmentCompliance);
              captureEquiptId = env-&gt;GetIntField(suplementaryInfo, fIdCaptureEquipmentId);
              imgWidth = env-&gt;GetIntField(suplementaryInfo, fIdImageWidth);
              imgHeight = env-&gt;GetIntField(suplementaryInfo, fIdImageHeigth);
              imgHorizontalResolution = env-&gt;GetIntField(suplementaryInfo, fIdImageHorizontalResolution);
              imgVerticalResolution = env-&gt;GetIntField(suplementaryInfo, fIdImageVerticalResolution);
              fingerPos = env-&gt;GetIntField(suplementaryInfo, fIdFingerPosition);
  
              memset(&amp;suplementaryInfo, 0x00, sizeof(suplementaryInfo));
  
              supInfo.version = ver;
              supInfo.captureCBEFFPid = captureCbeffpId;
              supInfo.captureEquipmentCompliance = captureEquiptCompliance;
              supInfo.captureEquipmentId = captureEquiptId;
              supInfo.fingerPosition = fingerPos;
              supInfo.imageHeight = imgHeight;
              supInfo.imageHorizontalResolution = imgHorizontalResolution;
              supInfo.imageVerticalResolution = imgVerticalResolution;
              supInfo.imageWidth = imgWidth;
  
          }
  
          returnStatus = pConvertTemplate(eInputTemplateEnvelopeType, 
                                         eInputTemplateDataType, (const void *)inputTemplate, (uint32)inputLength, 
                                         eOutputTemplateEnvelopeType, 
                                         eOutputTemplateDataType, 
                                         outputData != NULL ? (void *)outputTemplate : NULL,                                     
                                         (uint32 *)&amp;outputLength,
                                         suplementaryInfo != NULL ? (const void *)&amp;supInfo : NULL);
  
          env-&gt;SetStaticIntField(cls, fIdOutputLength, outputLength);   // It also crashes in windows7
  
          return returnStatus;
  
      }
      else
          return returnStatus;
  }
  </code></pre>
  
  <p>and here's the enum of the third party library in which JNI referring to:<code>typedef enum _tag_BCTemplateDataType {
       BCT_NOT_SPECIFIED =  -1,<br>
       BCT_NONE =  0,<br>
       BCT_UPEK_LEGACY,<br>
       BCT_UPEK_ALPHA,<br>
       BCT_UPEK_BETA,<br>
       BCT_UPEK_AUTO,<br>
       BCT_ANSI,<br>
       BCT_ISO_FMR,<br>
       BCT_ISO_FMC_NORMAL,<br>
       BCT_ISO_FMC_COMPACT,<br>
       BCT_ABAPI,<br>
       BCT_LAST<br>
  } BCTemplateDataType;</code></p>