Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. Run Time Error in 'return functions->FindClass(this, name)'

Run Time Error in 'return functions->FindClass(this, name)'

Scheduled Pinned Locked Moved Java
helpc++
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ravi120486
    wrote on last edited by
    #1

    Hi all, Iam getting run time error in following function in jni.h: return functions->FindClass(this, name); Following is the FindClass() function call fron my cpp file: cls = (env)->FindClass(servParams[i].lib); Plz help , I am new to JNI Programming. :(

    L 1 Reply Last reply
    0
    • R ravi120486

      Hi all, Iam getting run time error in following function in jni.h: return functions->FindClass(this, name); Following is the FindClass() function call fron my cpp file: cls = (env)->FindClass(servParams[i].lib); Plz help , I am new to JNI Programming. :(

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What is the actual error code or message that you receive? Also check the values of the various parameters you send to your functions. I also do not see the connection between the above two statements, the first accepts two parameters and the second passes only one.

      It's time for a new signature.

      R 1 Reply Last reply
      0
      • L Lost User

        What is the actual error code or message that you receive? Also check the values of the various parameters you send to your functions. I also do not see the connection between the above two statements, the first accepts two parameters and the second passes only one.

        It's time for a new signature.

        R Offline
        R Offline
        ravi120486
        wrote on last edited by
        #3

        Actually in jni.h following is the definition of FindClass

        jclass FindClass(const char *name) {
        return functions->FindClass(this, name); }

        Following is the Error message I am getting at 'FindClass(this, name)': Unhandled exception at 0x60edf3a0 (xxx.dll) in yyy.exe: 0xC0000005: Access violation reading location 0x00000000.

        L R 2 Replies Last reply
        0
        • R ravi120486

          Actually in jni.h following is the definition of FindClass

          jclass FindClass(const char *name) {
          return functions->FindClass(this, name); }

          Following is the Error message I am getting at 'FindClass(this, name)': Unhandled exception at 0x60edf3a0 (xxx.dll) in yyy.exe: 0xC0000005: Access violation reading location 0x00000000.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          OK so trying to read memory address 0 indicates you have an uninitialized pointer. Check your code to see where your pointers are set up. More specifically check the code where you are calling FindClass() and ensure that your name parameter actually points to something.

          It's time for a new signature.

          1 Reply Last reply
          0
          • R ravi120486

            Actually in jni.h following is the definition of FindClass

            jclass FindClass(const char *name) {
            return functions->FindClass(this, name); }

            Following is the Error message I am getting at 'FindClass(this, name)': Unhandled exception at 0x60edf3a0 (xxx.dll) in yyy.exe: 0xC0000005: Access violation reading location 0x00000000.

            R Offline
            R Offline
            ravi120486
            wrote on last edited by
            #5

            Hey Richard, Here in 'FindClass(this, name)' name parameter is pointing to some value but 'this' pointer is pointing to 0x00000000. Plzz help........

            L 1 Reply Last reply
            0
            • R ravi120486

              Hey Richard, Here in 'FindClass(this, name)' name parameter is pointing to some value but 'this' pointer is pointing to 0x00000000. Plzz help........

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              ravi120486 wrote:

              Plzz help.

              You will need to show some of your code, both Java and C for me to have any possibility of seeing how you are getting to this point. BTW please don't rely to your own messages as I don't get a notification of the update.

              It's time for a new signature.

              R 1 Reply Last reply
              0
              • L Lost User

                ravi120486 wrote:

                Plzz help.

                You will need to show some of your code, both Java and C for me to have any possibility of seeing how you are getting to this point. BTW please don't rely to your own messages as I don't get a notification of the update.

                It's time for a new signature.

                R Offline
                R Offline
                ravi120486
                wrote on last edited by
                #7

                I am not posting the entire code,Tell me if its sufficient Following is my Code:

                int MyAPI(Parameters* Params, int i) {
                .
                .
                .
                JNIEnv *env;
                JavaVM *jvm;
                JavaVMInitArgs vm_args;
                char clspath[400]="-Djava.class.path=";

                resCheckVM = JNI\_GetCreatedJavaVMs(&jvm, bufLen, &nVMs);
                if( resCheckVM < 0 || nVMs < 1 )
                {
                .
                .
                .
                 JNI\_GetDefaultJavaVMInitArgs(&vm\_args);
                 fflush(stdout);
                 res = JNI\_CreateJavaVM(&jvm,(void\*\*)&env,&vm\_args);
                 if (res < 0)
                     fprintf(stderr, "Failed to Create JVM.\\n");
                 }
                else
                {
                 fflush(stdout);
                 res = (jvm)->AttachCurrentThread((void\*\*)&env, NULL);
                 if (res < 0)
                   fprintf(stderr, "Failed attaching current thread to JVM.\\n");
                 }
                	 
                cls = (env)->FindClass(Params\[i\].lib);
                
                if (cls == 0)
                {
                  fprintf(stderr, "Can't find Prog class \\n",Params\[i\].lib);
                  return 1;
                }
                    {
                      fprintf(stderr, "Can't find function \\n");
                      return 1;
                     }
                

                .
                .
                .

                	 return 0;
                

                }

                Here I am getting this message "Failed to Create JVM." Then a run time error at FindClass(Params[i].lib).

                L 2 Replies Last reply
                0
                • R ravi120486

                  I am not posting the entire code,Tell me if its sufficient Following is my Code:

                  int MyAPI(Parameters* Params, int i) {
                  .
                  .
                  .
                  JNIEnv *env;
                  JavaVM *jvm;
                  JavaVMInitArgs vm_args;
                  char clspath[400]="-Djava.class.path=";

                  resCheckVM = JNI\_GetCreatedJavaVMs(&jvm, bufLen, &nVMs);
                  if( resCheckVM < 0 || nVMs < 1 )
                  {
                  .
                  .
                  .
                   JNI\_GetDefaultJavaVMInitArgs(&vm\_args);
                   fflush(stdout);
                   res = JNI\_CreateJavaVM(&jvm,(void\*\*)&env,&vm\_args);
                   if (res < 0)
                       fprintf(stderr, "Failed to Create JVM.\\n");
                   }
                  else
                  {
                   fflush(stdout);
                   res = (jvm)->AttachCurrentThread((void\*\*)&env, NULL);
                   if (res < 0)
                     fprintf(stderr, "Failed attaching current thread to JVM.\\n");
                   }
                  	 
                  cls = (env)->FindClass(Params\[i\].lib);
                  
                  if (cls == 0)
                  {
                    fprintf(stderr, "Can't find Prog class \\n",Params\[i\].lib);
                    return 1;
                  }
                      {
                        fprintf(stderr, "Can't find function \\n");
                        return 1;
                       }
                  

                  .
                  .
                  .

                  	 return 0;
                  

                  }

                  Here I am getting this message "Failed to Create JVM." Then a run time error at FindClass(Params[i].lib).

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  ravi120486 wrote:

                  Here I am getting this message "Failed to Create JVM."

                  Well, I don't think anything will work after this. If you have not managed to instantiate the JVM then your application should die as there is nothing further it can do.

                  It's time for a new signature.

                  R 1 Reply Last reply
                  0
                  • L Lost User

                    ravi120486 wrote:

                    Here I am getting this message "Failed to Create JVM."

                    Well, I don't think anything will work after this. If you have not managed to instantiate the JVM then your application should die as there is nothing further it can do.

                    It's time for a new signature.

                    R Offline
                    R Offline
                    ravi120486
                    wrote on last edited by
                    #9

                    Hey Richard, Can u tell me the reasons why JVM creation might have failed , so that i can loook for it . Regards, Ravi

                    L 1 Reply Last reply
                    0
                    • R ravi120486

                      Hey Richard, Can u tell me the reasons why JVM creation might have failed , so that i can loook for it . Regards, Ravi

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      You should check the JNI error code returned from your call to JNI_CreateJavaVM(); I would also check the values of your input parameters prior to the call to ensure all are correct.

                      It's time for a new signature.

                      1 Reply Last reply
                      0
                      • R ravi120486

                        I am not posting the entire code,Tell me if its sufficient Following is my Code:

                        int MyAPI(Parameters* Params, int i) {
                        .
                        .
                        .
                        JNIEnv *env;
                        JavaVM *jvm;
                        JavaVMInitArgs vm_args;
                        char clspath[400]="-Djava.class.path=";

                        resCheckVM = JNI\_GetCreatedJavaVMs(&jvm, bufLen, &nVMs);
                        if( resCheckVM < 0 || nVMs < 1 )
                        {
                        .
                        .
                        .
                         JNI\_GetDefaultJavaVMInitArgs(&vm\_args);
                         fflush(stdout);
                         res = JNI\_CreateJavaVM(&jvm,(void\*\*)&env,&vm\_args);
                         if (res < 0)
                             fprintf(stderr, "Failed to Create JVM.\\n");
                         }
                        else
                        {
                         fflush(stdout);
                         res = (jvm)->AttachCurrentThread((void\*\*)&env, NULL);
                         if (res < 0)
                           fprintf(stderr, "Failed attaching current thread to JVM.\\n");
                         }
                        	 
                        cls = (env)->FindClass(Params\[i\].lib);
                        
                        if (cls == 0)
                        {
                          fprintf(stderr, "Can't find Prog class \\n",Params\[i\].lib);
                          return 1;
                        }
                            {
                              fprintf(stderr, "Can't find function \\n");
                              return 1;
                             }
                        

                        .
                        .
                        .

                        	 return 0;
                        

                        }

                        Here I am getting this message "Failed to Create JVM." Then a run time error at FindClass(Params[i].lib).

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        Ravi, I have been doing some more testing and figure that some of your code is not needed and some needs correcting.

                        • The call to JNI_GetCreatedJavaVMs() will never succeed as you do not have any created VMs at that point. Also this call is not used in newer versions so can be removed.
                        • The call to JNI_GetDefaultJavaVMInitArgs() is no longer necessary and does not serve any purpose.
                        • Before calling JNI_CreateJavaVM() you need to initialize your vm_args structure with the correct values as described here[^]

                        It's time for a new signature.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups