Why does using a static jclass variable within a method crash the JVM?

I have some native code, that in a single thread, loops over a Java method. To improve performance, I tried this:
    static jclass clazz = env->FindClass("foo");
    /*FIXME: GetStaticMethodID crashes with "Bad global or local reference"*/
    jmethodID mid = env->GetStaticMethodID(clazz, "makeEvent", sig);But with the static declaration of clazz, the JVM crashes on the second iteration. Why? Is this really any different then using a C++ member field ?
My loop is really a bit more complicated then this, in that it starts several calls up. I hate the idea of
A) actually calling FindClass every iteration.
B) passing the clazz pointer through 3 layers of calls, just to avoid calling FindClass
Is there a better way?
Thanks!

Well I tried this, and it does not compile, becuase NewGlobalRef returns jobject not jclass.
Yes "jclass" is a pointer to a c++ object jclass, and jclass extends _object. However,
static jclass myGlobalRef dynamic_cast<jclass>( NewGlobalRef (myJClass));Does not compile either. The error is
error C2683: 'dynamic_cast' : '_jobject' is not a polymorphic type
static jclass myGlobalRef static_cast<jclass>( NewGlobalRef (myJClass));
DOES compile, but it is very dangerous. And using static_cast when dynamic_cast fails is a super-bad idea.
Just for laughs, I tried it anyway, and when I use -Xcheck:jni, the JVM dies with a fatal error.
Edited by: charlweed on Sep 19, 2009 3:56 PM
Typo

Similar Messages

  • Why does useful features are limited to few adapters?

    Why does useful features are limited to few adapters?
    For eg : File receiver CC has a option to stop Empty messages from being processed.
    This is not available in SOAP receiver.
    Is it possible to have a standard adapter module in SOAP receiver CC that will achieve this?
    Regards,
    Venkat.

    >
    Venkat A wrote:
    > Why does useful features are limited to few adapters?
    > For eg : File receiver CC has a option to stop Empty messages from being processed.
    > This is not available in SOAP receiver.
    Thats for SAP to answer i guess
    Well initially there was no option in the File adapter to handle empty messages but as requirement grew and more and more customers/consultants were in need to handle such a functionality, SAP brought it in through a SP release
    Maybe if this particular requirement of your finds popularity, then SAP might come up with a inbuilt solution
    >
    > Is it possible to have a standard adapter module in SOAP receiver CC that will achieve this?
    >
    > Regards,
    > Venkat.
    in you case why do you need to send the SOAP receiver a empty message??
    If you need to handle it then the best is to do some workaround in the mapping and have a field in your target structure indicate that it is a empty message (something like a flag) and then do the routing logic based on this flag.

  • Why, after using my Apple ID and Pswd, and clicking on the arrow, does nothing happen -- cannot access iCloud?

    Using Windows Vista on my PC, why, after using my Apple ID and Pswd, and clicking on the arrow, does nothing happen -- cannot access my iCloud calendar?

    i'm having the same problem

  • Why does my iPhone 5 take very grainy flash photographs in the dark will a hard reboot be safe to do to try to fix or is it a hardware issue?

    Why does my iPhone 5 take very grainy flash photographs in the dark will a hard reboot be safe to do to try to fix or is it a hardware issue?
    And By hard boot I mean holding the home and power button down at the same time for 10 seconds or whatever
    I see other people have these grainy flash photographs if you try to take a picture in darkness the picture comes out very dark and grainy I thought the software would ultimately fix this but it's been going on for over a year I usually take my photographs in daylight but I need this to be fixed
    If it is a hardware issue I hope Apple will replace my iPhone 5 because I was just waiting for one of the iOS updates to fix it I bought my phone in November 2012 its the iPhone 5
    Please help or advise if you can was this just a software or hardware issue I know Apple was aware of it but I was advised that iOS update would fix it but obviously not
    Is it safe to do a hard boot on my iPhone five by holding the power and home button at the same time for 10 or 20 seconds I saw someone said that fixed there's at least temporarily
    I'm typing this on my iPhone five right now why do the words go off to the left and right no matter if I hold the phone vertical or horizontal the words bleed off to left right so for me to proofread it I have to move my text left to right to proof read it
    Thank you

    The flash on a smartphone camera is tiny. It only lights up a very small area right in front of the camera. It won't light up the whole scene.
    Have you seen the size of the flash on a professional camera? Even they can't light a whole scene in the dark.
    Fact is, a smartphone camera is not capable of taking good photos in the dark, even with the flash.
    You'll need to buy and learn how to use a professional, dedicated SLR camera to be able to take good photos in the dark. It is not easy.

  • Why does my form data gets cleared out when clicking on the back button.

    Can someone explain why does my form selections get cleared out when clicking on the back button.
    I have a JSP page that displays a form with some selections and text boxes. I populate the page and submit the request. The action on the submit call another jsp page, which processes the data and displays the results via a <jsp:include> statement which calls the results page. When clicking on the back button from the results page, it returns me to the form page, but the selections are cleared out.
    1. Is there something in my calling of the pages that causes this behavior and can I prevent it?
    I notice that the behavior is different when using the IE 6.0 version Netscape 7.1. IE clears the page Netscape 7.1 retains the settings.
    If I cannot prevent this behavior does that mean I will have to save the state of the form data. And if I have to save the form data, what would be the easiest method of doing this. I'm a beginner to JSP and Java, but have some ASP experience. I don't understand why the back button in a JSP request clears the form data but a regular HTML page does not can someone explain?
    THANKS.

    the browser doesn't have to remember what you submitted and fill that back in.
    you can't prevent it unless you can ensure a new request to the server in which you can fill the default values in there.

  • HT3728 Base station error, air port utility was unable to find my airport device. Why does it say this when it recognizes my airport on the computer? Yellow light has been on

    Base station error, air port utility was unable to find my airport device. Why does it say this when it recognizes my airport on the computer? Yellow light has been on

    On the older version of the AE you can still use older airport utility.
    But once you load the new one you cannot easily go back.. you can load an older 5.6 version though.. instructions below.
    For 6.3 you need to run ipv6 local link.
    see http://support.apple.com/kb/TS4597
    How to load 5.6 into ML.
    1. Download 5.6 for Lion.
    http://support.apple.com/kb/DL1482
    Click to open the dmg but do not attempt to install the pkg.. it won't work anyway.
    Leave the package open on the desktop so you can see the file. AirportUtility56.pkg
    2. Download and install unpkg.
    http://www.timdoug.com/unpkg/
    Run unpkg on the desktop.. If your Mac refuses to run the software, because it wasn’t downloaded from the Apple store, go to security in preferences and allow other software to work.. this is limitation of trade methinks. You can set back later if you like.
    Now drag the AirPortUtility56.pkg file over to unpkg.. and it will create a new directory of the same name on the desktop.. in finder, open the new directory, drill down.. applications, utilities .. there lo and behold is Airport utility 5.6 .. drag it to your main utilities directory or just run it from current location.
    You cannot uninstall version 6 (now 6.3 if you updated) so don't try.. and you cannot or should not run them both at the same time.. although I have had no problems when doing so.

  • Why does iPhone videos take so long to come up on the Apple TV?

    Why does iphone videos take so long to come up on the apple tv?
    1080P has a large file size but are there ways to get it to start to play faster?
    Hard wiring it into the LAN helped a bit but what is really slowing it down? WPA2?
    Thanks,

    could be the wifi speed as in 56Mbit vs. newer 300Mbit version
    or interfearing from other wifi networks which use the same channel
    or microwave or dect phones which also operate on the 2.4Ghz band

  • Why does my 4s phone mute itself? I've reset the setting like other posts have suggested.

    Why does my 4s phone mute itself? I also have a hard time hanging up after a call. The screen goes blank like it's in a sleep mode. I have to use 2 hands to make it hang up--one to hold the home button and the other to hit the end bar. I've "Reset All Settings" in General Settings like other posts have suggested. This worked for a short period of time but now the phone is back to muting itself. Why does this happen?

    Basic troubleshooting steps clearly outlined in the User Guide are restart, reset, restore from backup, restore as NEW.
    If you've been through ALL these steps and you still have problems, then you'll need to bring your phone into Apple.

  • WHY DOES IT ACT LIKE I AM OPENING ITUNES UP FOR THE FIRST TIME

    WHY DOES IT ACT LIKE I AM OPENING ITUNES UP FOR THE FIRST TIME

    dewin1or wrote:
    I want to extend the length of the song by repeating the first 28 measures.
    split the region at the 28th measure
    http://www.bulletsandbones.com/GB/GBFAQ.html#split
    (Let the page FULLY load. The link to your answer is at the top of your screen)
    then select only the first region and option-drag it to the end of the song

  • Why does my Ipad keep going black and then back to the apple logo.  It eventually goes to the start page but then blacks out again.  I have already rebooted several times with no luck!!

    Why does my Ipad 2 keep going black ahd back to the apple logo.  It eventually goes to the home screen and allows me to try something else but after about 30 seconds it happens again.  I have already rebooted several times? 

    Make Sure iOS is updated to the latest version
    Reboot the device by pressing and holding down the home and sleep/wake buttons (power) at the same time until the apple logo appears on the screen, then let go.
    If that doesn't work then reset the device by going to settings/general/reset/reset all settings

  • Why does Flash Player keep sending me notifications to update to the version I already have?

    Why does Flash Player keep sending me notifications to update to the version I already have? The result is always an error message telling me that the version is already running. (Desktop Computer; Windows Vista OS; Firefox; Adobe Flash Version 11.8.800.94)

    I don't know; can you post a screenshot of such a notification?
    Did you update both ActiveX (for Internet Explorer) and plugin (for Firefox)?

  • Why does siri come on by itself while it sits on the table no one touching it?

    why does siri come on by itself while it sits on the table no one touching it?

    michael jfromtaunton wrote:
    why does siri come on by itself while it sits on the table no one touching it?
    If you're not running iOS 8 as you describe you are not, and Siri keeps coming on, this could be a hardware failure of the Home Button.
    Try these steps:
    Basic Troubleshooting Steps when all else fails
    - Quit the App by opening multi-tasking bar, and swiping the App upward to make it disappear.  (For iOS 6 older, hold down the icon for the App for about 3-5 seconds, and then tap the red circle with the white minus sign.)
    - Relaunch the App and try again.
    - Restart the device. http://support.apple.com/kb/ht1430
    - Reset the device. (Same article as above.)
    - Reset All Settings (Settings > General > Reset > Reset All Settings)
    - Restore from backup. http://support.apple.com/kb/ht1766 (If you don't have a backup, make one now, then skip to the next step.)
    - Restore as new device. http://support.apple.com/kb/HT4137  For this step, do not re-download ANYTHING, and do not sign into your Apple ID.
    - Test the issue after each step.  If the last one does not resolve the issue, it is likely a hardware problem.

  • Why does my iphone says its blocked and nothing appears on the screen

    why does my iphone says its blocked and nothing appears on the screen

    Its completly black on the screen and there is a voice saying the screen is blocked nothing seems to work to put the screen on it asks for a code but i cant see any numbers on the screen

  • Why does Siri keeps talking with every action I take on the iphone?

    Why does Siri keeps talking with every action I take on the iphone?

    Settings > General > Accessibility > Speak Selection > switch off here

  • Why does my I-Phone 4 calendar only show apptmnts from the last 90 days?  How can I see appointments prior to then?

    Why does my I-Phone 4 calendar only show apptmnts from the last 90 days?  How can I see appointments from prior to then?

    The Sync setting only appears if you are syncing your calendar with iCloud.  If you are syncing them to another service (such as Google) you would need to go your account with that service and see if you can change the setting there.
    If you are syncing your calendar with iCloud, you should see the Sync setting, and be able to tap and change it.

Maybe you are looking for

  • Just got a new 2.7 and wondered how to use optical out from g5

    i got 2408 motu and wanted to use apples optical ins and outs together 2408 i tried have not even figured out how to get the optical to work bare with me im switching over from protools .So explain the setup on how to use multiple sound cards in logi

  • Bring back Bars

    Since digital recording, especially file based recording, the use of Bars and Tone to follow through a workflow has gone out of fashion. There are a number of current threads in the forums with ' my export is too dark, too light, colour cast' type of

  • Relevant table for the mentioned feilds for mis report  ?

    Hi experts , Am extracting the data for MIS reports, As far as my requirement i need to find the relevant datasources based on this, i treid to extract this datasources like 0co_om_cca9 but am not geting all the relevant feilds. ->Document type -> po

  • How ro compare 2 chm files? or use track changes in xpj project?

    Hello, I'm using robohelp#7 and was wondering if there's a way to compare 2 output chm files in such a way that only shows the delta, i.e the changes made from previous version? alternatively, is there a way to see track changes in the xpj project? T

  • Post Moved Infinity-New-install-today

    Post moved to Inifinity Board  http://community.bt.com/t5/BT-Infinity/Infinity-New-install-today/td-p/682502 If you want to say thanks for a helpful answer,please click on the Ratings star on the left-hand side If the reply answers your question then