Accessing java fields from c++

I have created a JNI app that needs to access the fields of the java object but when I try to access them I get an error message saying "no such field."
When I created my header file with javah I got (JNIEnv *, jclass and jobject) as my parameter list not JNIEnv * and jobject like all the documentation does.
then i try to access the fields with :
fidZone = env->GetFieldID(cls, "zone","I");
which generates the error mentioned.
Any suggestions will be greatly appreciated.
Cheers.

1. Here is the native code:
#include <jni.h>
#include <stdio.h>
#include "worldfl.h"
//header for external DLL I want to access
#include "GDAit.h"
JNIEXPORT jlong JNICALL
Java_worldfl_TransProjectPt(JNIEnv *env, jclass cls, jobject obj)
jfieldID fidx, fidy, fidStr, fidZone, fidTrDir;
long zone, agd2gda, iResult = 0;
double transX, transY, newX, newY, accX, accY;
/* GET the X & Y values of the coords in the world file */
cls = env->GetObjectClass(obj);
printf("%ld\n", cls);
if (cls != NULL)
fidZone = env->GetFieldID(cls, "zone","I");
fidTrDir = env->GetFieldID(cls, "agd2gda","I");
fidx = env->GetFieldID(cls, "transX","D");
fidy = env->GetFieldID(cls, "transY","D");
/*fidStr = env->GetFieldID(cls, "filename","Ljava.lang.String");*/
transX = env->GetDoubleField(obj, fidx);
transY = env->GetDoubleField(obj, fidy);
zone = env->GetDoubleField(obj, fidZone);
agd2gda = env->GetDoubleField(obj, fidTrDir);
iResult = 0;//TransProjPt("f:\\coordcalcs\\A66 National (13.09.01).gsb", agd2gda, transX, transY, zone, &newX, &newY, &accX, &accY);
else
printf("Class is NULL\n");
//env->GetDoubleField(obj, fidx) = newX;
//env->GetDoubleField(obj, fidy) = newY;
return(iResult);
2. Yes it is defined as static
private native static long TransProjectPt(worldRead wr);

Similar Messages

  • (how) can I access Java APIs from web-page-hosted JavaScript?

    Can I access Java APIs from a web-page via JavaScript if I have a JRE installed on the client machine? And if so, how?
    Thanks in advance for your time and consideration.

    John L. wrote:
    Can I access Java APIs from a web-page via JavaScript if I have a JRE installed on the client machine? And if so, how?As far as I can remember that was actually possible in the very first versions of Netscape because Netscape really wanted to pretend Javascript and Java were meant to be used together. But they soon removed that functionality. Can you guess why?
    Because people were using the File/IO classes to easily steal or remove files on the harddrive, among other such niceties. You do NOT want to have such control from a web application. People will abuse it.

  • Accessing java objects from within javascript

    Hello,
    Anyone with an idea of a useful toolkit for accessing java objects from within javascript will be much appreciated.
    Thanks in advance,
    Antana.

    What do you mean by accessing Java objects? Do you mean interacting with an applet via JavaScript? Something else?

  • Accessing private fields from an subclass whoes parent is abstract.

    I seem not to be able to access some private fields from a subclass who's parent is abstract...
    here is some code to demonstrate this: (based on yawmark's code)
    import java.lang.reflect.*;
    import java.net.URLClassLoader;
    import java.io.*;
    import java.net.*;
    class PrivateReflection {
        public static void main(String[] args) throws Exception {
            Private p = new Private();
            File f=new File("test.jar");
            URL[] urls=new URL[1];
            urls[0]=f.toURL();
            URLClassLoader loader=new URLClassLoader(urls);
            Class c=loader.getClass();
    //        Class c=p.getClass();
            Field field = c.getField("packages");
            field.setAccessible(true);
            System.out.println(field.get(p));
    class Private {
        private String packages = "Can't get to me!";
        private void privateMethod() {
            System.out.println("The password is swordfish");
    }There is no need for a test.jar file to be created.
    I know for a fact that the ClassLoader abstract class defines a field called "packages" which is an HashMap.
    How do i access this private field?
    I am in the process of making a utility which re-compresses a inputed JAR using other compression methods than normal zip compression while still keeping the same functionality as the inputed JAR.
    I do have it working for Executable JARS: www.geocities.com/budgetanime/bJAR.html
    This old version only works for executable JARs and uses Bzip2 compression.
    I believe i have been able to solve all but one last problem to making re-compressed JARs which work as "library" JARs. This last problem is "removing" temporary prototype classes from the system loader and replacing them with the actual decompressed classes. As there seems not to be an nice way to do this i will have to manually remove references of the classes from the system class loader which is why i am asking this question.

    lol! i have solved my problem... it was because i was using the getField() method instead of the getDeclaredField() method.

  • Accessing Java Classes from Forms

    Is is possible to access a Java class from Forms? I have been
    creating an Active X control that returns a Java object, and from
    that I can call methods on that object, but I would really like
    to do that without having and Active X control in the mix. Any
    suggestions?
    null

    Oracle Developer Team wrote:
    : Robert Nocera (guest) wrote:
    : : Oracle Developer Team wrote:
    : : : hey robert -
    : : : Developer 6.0 provides this ability for web deployment.
    You
    : : can
    : : : insert your own custom Java components into your
    application
    : : and
    : : : they will appear in the application when it is run via the
    : web.
    : : : If you look at the documentation for 6.0, there are a few
    : : : section son Pluggable Java Components and JavaBeans that
    : : : describes what is provided and how you use the interfaces
    : and
    : : : classes we provide.
    : : : A whitepaper on this topic will be posted to the OTN
    : shortly,
    : : as
    : : : well as some samples that illustrate how to go about doing
    : it.
    : : : cheers!
    : : : -Oracle Developer Team-
    : : Thanks for the quick response. Is there any way to access
    : those
    : : classes without being in a web deployment. That's probably
    : not
    : : totally out of the question, but what we had in mind was
    : adding
    : : some Java Functionality (actually connectictivity to some
    EJBs
    : : that we have) to existing forms. Currently there forms are
    : not
    : : deployed in a "web" environment and are just run from the
    : forms
    : : runtime engine.
    : : -Rob
    : hey again robert -
    : there's no easy way (yet!) to call out from forms runtime
    : process to a Java application.
    : We've played around some with creating an ORA_FFI interface to
    : JNI and then wrappering this with PL/SQL code. We've been able
    : to make calling into an EJB running in 8i from a forms runtime
    : work using this approach.
    : Let me know if this is of interest to you and I can post the
    : stuff we've currently got. It's no more than a simple demo and
    : is not complete. It requires quite a bit of manual coding on
    : the PL/SQL side since the interface emulates JNI (FindClass,
    : GetMethodID, CallMethodID, etc.).
    : cheers!
    : -the Oracle Developer Team-
    I'd be interested in this ORA_FFI doc you've been playing with.
    Would you please email it to me or post it.
    null

  • WPC: Access Java beans from XSL

    Hi,
    How can we access custom Java beans from within the XSLs used to render WPC webforms? Do we have to implement a custom XSLT Helper? I am able to access standard Java classes using the <xmlns> tag but when I try to reference our custom classes the WPC editor throws a ClassNotFound exception. Any help will be appreciated.
    Thanks and Regards,
    Shibendra

    Hi,
    How can we access custom Java beans from within the XSLs used to render WPC webforms? Do we have to implement a custom XSLT Helper? I am able to access standard Java classes using the <xmlns> tag but when I try to reference our custom classes the WPC editor throws a ClassNotFound exception. Any help will be appreciated.
    Thanks and Regards,
    Shibendra

  • Accessing a field from a structure with out header line

    Hi Guys,
                 I am trying to assign a field from a structure type line of data to another field.
    This structure type line don't have a header line.
    here is the example.
    IT_EKKNU TYPE  MMPUR_EKKNU.
    when I use following statement..
    move IT_EKKNU-kostl to e_cekko-kostl.
    Iam getting error "IT_ENKKNU is not a structure or Internal table with header line.
    How to access the fields in structure IT_EKKNU.
    Thank U for ur time.
    Cheers
    S Kumar

    Here IT_EKKNU is an internal table without Header line.
    You can use a structure for assignment.
    DATA: IT_EKKNU TYPE MMPUR_EKKNU,
               wa_ekknu type    ekknu.
    read table it_ekknu into wa_ekknu........
    move wa_EKKNU-kostl to e_cekko-kostl.
    *modify the code for your conditions*.

  • Accessing java classes from javascript

    Hi,
    I have the following javascript function
    function testjava {   
        var myString = new java.lang.String("Hello world"); // line 1
        alert("len:"+myString.length()); // line 2
    }It gives me a error at line 1 saying "'java' is undefined" in IE browser 5.5 sp2. But, both the lines execute correctly in netscape 6.
    Can someone please help..
    Thanks,
    Vijay.

    It seems that IE 5.5 doesn't support accessing java classes in JavaScript, so try to install IE 6 to see if it works or maybe, you doesn't have installed propertly support for JVM in IE.

  • Access Java object from Javascript

    Hi
    I'm trying to invoke a Java object from Javascript (scriptengine and all that).
    I want to add scripting features to a GeneXus Java generated app... and I have very basic skills on java too. Sorry for that ;o).
    This is the java code to pass "params" to the scriptengine:
    engine.put("remoteHandle",remoteHandle);
    engine.put("context", context); The remoteHandle (int) and context (com.genexus.ModelContext) pass trough all the gx-java generated programs.
    This javascript works fine:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle).execute( ) ;The remoteHandle conversion is ok (javascript-number to int). The context is optional.
    But if I want to pass context:
    importClass(Packages.uftestjs);
    new uftestjs(remoteHandle, context).execute( ) ;Fails with this:
    "javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Java constructor for 'uftestjs' with arguments 'number,javax.script.SimpleScriptContext' not found."
    Obviously, no conversion is possible with context (javax.script.SimpleScriptContext to com.genexus.ModelContext).
    There is some way to reference de original context, by the object Id??? or something like that???
    Thanks in advance for any replies!!!
    Greetings from Chile. (I hope you can understand my english!)

    Hi
    Well, since this topic is about java programming I think the place is right here.
    (I use some tricks to embed java statements in genexus objects...)
    I will try to get some help at Artech (GX) on how to build something... to get the conversion needed.
    But they are not focussed on support this kind of questions.
    Anyway, I want to know: do I can to reference an object by the objId?
    I want to code something like this:
    com.genexus.ModelContext context =
                     (com.genexus.ModelContex)getTheObjectFromTheJVM(theObjectId);(powered by google translator, ha!)

  • Accessing input field from the JSP in dynpage

    HI all,
          I am trying to access the input field of the jsp page in my JSPDynpage but it is always return null.My Input is a normal HTML element not a HTMLB element
    JSP File :
         <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
      <hbj:form id="myFormId" >
         <div class="content">
            <table cellpadding="2" cellspacing="2">
                        <tr>
                               <td>
                                  <label for="name"><strong>UserName:</strong></label><span id="info_name">(This field is required)</span><br />                           
                                     <input name="name" id="name" size="10" maxlength="10" type="text" />
                               </td>
                        </tr>
                        <tr>
                             <td>
                                  <label for="email"><strong>EmailID:</strong></label><span id="info_email">(This field is required)</span><br />                           
                                     <input name="email" id="email" size="20" maxlength="20" type="text" /></td>
                        </tr>\
    </Table>
    JSPDynpage:
           InputField myInputField = (InputField) getComponentByName("name");
         if (myInputField != null) {
          name = myInputField.getValueAsDataType().toString();
                   InputField myInputField1 = (InputField) getComponentByName("email");
         if (myInputField1 != null) {
          name = myInputField1.getValueAsDataType().toString();
    In both the cases myInputField and myInputField1 are null . My Question is what should be the parameter that i need to pass for getComponentByName method.
    Regards,
    Raj.

    hi,
    The way you are trying to get the input field value works good with hbj type elements.
    either you change your input field to an hbj one or use java script inside your jsp page to catch the value
    like
    for HTML:
    [HTML Input Field|http://www.w3schools.com/HTMLDOM/met_doc_getelementbyid.asp]
    and for HTMLB
    refer this link:
    [SAP HTMLB GuideLines|http://www.sapdesignguild.org/resources/htmlb_guidance/index.html]
    Regards,
    Srinu

  • Accessing Java objects from C++ client

    I have a number of Java CORBA server objects that I have deployed to an 8.1.7 database.
    I can invoke these objects from a Java client with no problem, but I also need to access them from a C++ client.
    I have used idl2cpp from VisiBroker for C++ (version 4.5) to generate the client stubs, and I've downloaded the interop.tar file from http://technet.oracle.com/products/oracle8i/htdocs/jserver_faq/interop.tar
    The problem that I have is that I have not been able to build a client program because login.lib from interop.tar generates conflicts at link time. I've tried everything that I can think of, but I always end up with either missing references or multiply defined symbols. I've tried building using both MS Visual C++ and Borland C++Builder, but with no success.
    Has anybody succeeded in building a C++ client? Surely it shouldn't be this difficult?
    Thanks,
    Tony

    Thank u for taking care of me
    But the hint given by u is not apt to my query.
    If any new suggestion pls send again

  • Access java properties from C++/JNI program

    Hello all,
    Is it possible to access the Java properties of a JNI VM from a C++ program?
    If so, could the code or process be explained to me.
    I want to be able to identify a specific VM that is retrieved by the JNI_GetCreatedJavaVMs
    call. I set a user property when the VM was created, and would like to verify its value
    before calling AttachCurrentThread.
    Thanks in advance.
    Mark

    Are you saying that you set a system property (via System.setProperty() or -D)?
    If so, just use the JNI invocation API to call System.getProperty().
    Without error checking, that looks something like this:bool isMySystem( JNIEnv* env ) {
      const string PropertyName = "IsMySystem";
      jclass systemClass = env->FindClass( "java/lang/System" );
      jmethodID getPropertyMethod = env->GetStaticMethodID( systemClass, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;" );
      jstring propertyNameString = env->NewStringUTF( PropertyName.c_str() );
      jstring propertyString = env->CallStaticObjectMethod( systemClass, getPropertyMethod, propertyNameString );
      if ( propertyString == 0 ) {
        return false;
      const char* property = env->GetStringUTFChars( propertyString, 0 );
      boolean isMine = ! strcmp( property, "Yes" );
      env->ReleaseStringUTFChars( propertyString, property );
      return isMine;
    }Using Jace, http://jace.reyelts.com/jace (a free, open-source toolkit), this would look more like:bool isMySystem() {
      String property = System::getProperty( "IsMySystem" );
      return property.isNull() ? false : prop == "Yes";
    }In the end, Jace ends up making all of the exact same calls, but you can see how much easier it is to use.
    God bless,
    -Toby Reyelts

  • Access required fields from another datasource

    Hi,
    I need to have contract information for Sales Orders (i.e. doc_type / doc_categ / doc_categr / refe_doc) in Billing Document ODS (source - 2lis_13_vditm).
    This data exists in my Sales Order Item ODS (source - 2lis_11_vaitm). What is the most efficient way of getting this data?
    I am considering doing a lookup in the update rules of the Billing Document ODS from the Sales Order Item ODS. Will this do the trick?
    Thanks,
    Milind

    Hi,
    I think this all fields are already present in the billing extractor.
    doc_type / doc_categ / doc_categr / refe_doc...this all attributes of sales are defenatley in the billing extractor just type to explore it...I am not sure what is reference doc...but rest three are there..and are commonly used from this data source....just try it out.
    There is something called as SD document category,Sales document type etc. present in the 2LIS_13_VDITM which contains the values for sales doc only.check for the fields like PVTYP,AUTYP etc.I dont remember it exactly the field name but its there and I have used it from 2LIS_13_VDITM...no need to look into sales extractor for this.
    also doing a look up like this will create a huge performace issues as for every billing doc loaded you will have to scan the whole sales item DSO again and again.will not advice to do that.
    Thanks
    Ajeet

  • Accessing Java Classes from Webservice Stubs

    So far I have been able to call a web service and copy the appropriate directories and files to the designated class path.  I can also successfully access a class file like this:
    MyObject = CreateObject("java", "ca.x.y.z.TestCollection.TestItem");
    However, whenever I try to do something with that variable, I get a white screen.  Any text that should have appeared before the command, will appear, but nothing appears afterwards, not even debugging info.  Here are a couple of commands that will cause this to happen.
    <cfdump var = "#MyObject#">
    MyObject = CreateObject("java", "ca.x.y.z.TestCollection.TestItem").init();
    x = MyObject.init();
    Anybody have any ideas?

    Ah, nothing like a fresh set of eyes to remind of the fundamentals.  Thank you for that.
    I actually could create a normal error by calling a method incorrectly.  I would see the grey box and my debgging info would appear.  However, if I did something I expected to succeed, it would seem to stop.  Any text above that command would appear.  No error message, no de-bugging.
    But I didn't think to look in our error log.  I see things like:
    Could not initialize class com.microsoft.schemas._2003._10.Serialization.Arrays.ArrayOfstring
    or
    org.apache.axis.description.TypeDesc.(Ljava/lang/Class;Z)V
    At least it's not a mystery anymore.  Thanks again for suggesting the error log.

  • Accessing Java HttpServer from PHP;

    Hello all,
    I have created an httpserver using 'com.sun.net.httpserver'. Everything works fine except one thing.
    When i make this simple call from PHP (http://localhost:8081/something outputs an XML file):-
    $url = 'http://localhost:8081/something'; 
    $xml = simplexml_load_file($url); 
    print_r($xml); Nothing appears and it times out after sometime.
    However, while the browser is 'trying' to get the result (from PHP file) if i 'stop' my HttpServer (Java) the result suddenly appears. I am very sure i close all the streams i opened. Does anyone have any idea?
    Thanks
    Neville

    So on doing some debugging i realized that the http thread that started executing may have not exited correctly. That may explain the fact that when i shut the java server down explicitly while the 'php' code waits for some response, the response suddenly appears.
    While creating the server i am using:-
    server.setExecutor(Executors.newCachedThreadPool());In ThreadPoolExecutor.class
    Runnable getTask() { ....
    if (state == SHUTDOWN)  // Help drain queue
        r = workQueue.poll();
    else if (poolSize > corePoolSize || allowCoreThreadTimeOut)
        r = workQueue.poll(keepAliveTime, TimeUnit.NANOSECONDS);
    else
       r = workQueue.take();
    if (r != null)
        return r;
    if (workerCanExit()) {
    ...Using the debugger tool took me to the class ThreadPoolExecutor.class which seems to be the bottleneck; This condition is true (poolSize > corePoolSize || allowCoreThreadTimeOut(=false)) and it starts polling. I think maybe this is causing the problem and if it exited maybe the result would appear. Even if the corePoolSize is more than poolsize it seems to be getting stuck in r = workQueue.take();.
    I dont know how it works ok with a browser but hangs when PHP request comes into the picture. Strange...
    Thanks
    Neville

Maybe you are looking for