Getting the text of a java exception into C++ via JNI - how ?

I have a C++ application that needs to create and call Java objects. If there is an exception in a Java method I want to be able to get the text of the exception's message for reporting an error to the C++ application user. The problem is, I can't get the methodID of the 'getMessage' method in the Throwable class.
This is how I am tryng to get it:
// Relevant exception-handling variables:
jthrowable exceptionHandle;
jclass jThrowableClass;
jmethodID methodID;
//Invoke the Java object
env->CallVoidMethod( obj, methodID, args );
//Check for an exception
if ( (exceptionHandle = env->ExceptionOccurred()) != NULL )
jThrowableClass = env->GetObjectClass( exceptionHandle );
methodID = env->GetMethodID( jThrowableClass, "getMessage", "()Ljava/lang/String;" );
// methodID is always NULL -- why??At this point, it can't go any further because the methodID is always NULL.
I've tried several things, such as explicitly including rt.jar in the classpath when initializing the VM (I'm using JDK 1.3.1 and JNI 1.2) as well as copying rt.jar to the directory where the application's java VM code is at, but no luck there. I've also tried FindClass( "java/lang/Throwable") but that returned NULL so doesn't get as far as the code example here.
How do you get the methodID of a method in a java language class like java.lang.Throwable ? Is there some initialization you need to do with the classpath ?
Many thanks,
Colm.

When you program in Java you can use java.lang.reflect.
For example, having a method named "met1" with 2 parameters, you can assign an object Method in this way:
import java.lang.reflect.Method;
Method comp = o1.getClass.getMethod("met1", param1.getClass(), param2.getClass());So with Throwable you could try something like: Throwable.class.getMethod("getMessage")Sorry but I am not so strong in C++ and I cannot give you help about it.
The Java API documentation for the reflect package is at: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/package-frame.html
Hoping to be helpful
giangio

Similar Messages

  • Is there a way to get the text written into a text object in an AWTFrame

    I am trying to get the text written into the text box in the AWTFrame.
    I have tried the following:
    <pre> AccessibleTextInfo acinfo;
         AccessibleContextInfo actinfo;
         AccessibleTextItemsInfo acttinfo;
         actinfo = getContextInfoFromContext(ac);
         GetAccessibleTextInfo(vmID,ac,&acinfo,actinfo.x,actinfo.y);
         printf("char count =%i\n",acinfo.charCount);
         printf("OK so far\n");
         GetAccessibleTextRange(vmID,ac,0,MAX_STRING_SIZE,sData,MAX_STRING_SIZE);
         printf("text =%s\n",sData);</pre>
    The charCount is correct but the string returned is always null.
    Is this the right way to do this. If not then is there a correct way to get the text from a text box.

    881530 wrote:
    Looks like one of the accessbridge files was corrupted. I re-installed access bridge and it worked fineGlad to hear your problem is resolved. Definitely odd though, I'd expect things to crash and burn in stead of changing behavior.

  • How to get the text in a label which is imbeded in a JTextPane

    I have created a JTextPane that has 5 JLabels inserted in the text. I have attempted to get the text with the following code snippet.
    Component[] lbl = new Componennt[DisplayLetterPane.getComponentCount()];
    //         JTextPane DisplayLetterPane; is defined previously
             lbl = DisplayLetterPane.getComponents();
             int componentIndex = 0;
             String lblText = new String(((JLabel)lbl[componentIndex]).getText());I have run a dump of the sytledDocument of the JTextPane and I see the JLabel listed as a component.
    When this snippet is executed I get the following:
    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.text.ComponentView$Invalidator
    When I check the character where the component for the JLabel is located in the styled document it does not find an instanceof JLabel.
    How can I get the text from the labels.
    Thank you in advance!

    JTextPane jtp = new JTextPane();
              for (int i = 0; i <5; i++) {
                   jtp.add(new JLabel("labelText"+i));
              Component[] lbl = new Component[jtp.getComponentCount()];
    //      JTextPane DisplayLetterPane; is defined previously
          lbl = jtp.getComponents();
          int componentIndex = 0;
          for (int i = 0; i < lbl.length; i++) {
               System.out.println(((JLabel)lbl).getText());
    When I do like the above, it just works fine. Can u share a little bit more of your code?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to get the text in module pool program after f4 help

    Hi to all experts,
    My required is to get the text of a field when the user clicks on the f4 help text should be populated automatically beside the field
    how to do it

    >
    > the screen name is defined as t528t-plstx and while passing im using the same name in the POV module after what could be the reason;
    Hi in the POV module, first read the dynpro filed for which a text has to be displayed  (using FM- DYNP_VALUES_READ)and then update your Text Description field uing  the FM -'DYNP_VALUES_UPDATE
        dynpfields-fieldname  = 'FNAME'.                  "FNAME is the field for which POV is called
        append dynpfields.
        repid = sy-repid.
      call function 'DYNP_VALUES_READ'
           exporting
                dyname     = sy-cprog
                dynumb     = sy-dynnr
           tables
                dynpfields = dynpfields
           exceptions
                others.
       read table dynpfields index 1.
       fname = dynpfields-fieldvalue.
    *Fetxh the Text field into a local varaible.
        l_plstx = XXXXXXX. 
        dynpfields-fieldname    = 'T528T-PLSTX'.
        dynpfields-fieldvalue   =  l_plstx.
        APPEND dynpfields .
        CALL FUNCTION 'DYNP_VALUES_UPDATE'
          EXPORTING
            dyname               = sy-repid
            dynumb               = sy-dynnr
          TABLES
            dynpfields           =  dynpfields.
    This will update your text field dynamically.
    Regards,
    Rajesh

  • Getting the current time using java.sql.Time

    I need to set the current time in a database field. I tried the following code (using my logic) to set the current time. But, I end up getting "Jan 1, 1970" in the time field in the database.
    Here is the code :
    Calendar cal = Calendar.getInstance();
    Java.sql.Time now = java.sql.Time.valueOf(
              cal.get(Calendar.HOUR_OF_DAY) + ":" +
              cal.get(Calendar.MINUTE) + ":" +
              cal.get(Calendar.SECOND));
    What should I do to get the current time in the "now" variable? Right now, it ends up in the database as "Jan 1, 1970".
    Thanx in advance.

    Can you show me the code to do SimpleDateFormat?
    Assuming that I use the following skeleton to get the
    time value from the database, can you show me the
    code for the missing link (so as to display in the
    format "hh:mm:ss") ?
    java.sql.Time timeFromDb =
    obj.getActionTime();
    // The above code gets the "time" field from
    the database into "timeFromDb"
    // Use SimpleDateFormat to display the time
    java.text.SimpleDateFormat sdf = new
    java.text.SimpleDateFormat("hh:mm:ss");
    // Now what do I do with "sdf" and
    "timeFromDb" ?
    // Print out the time value
    System.out.printf("Time is : %s\n",
    .... );Hi,
    I don't know if you want 24h clock or not. This is the pattern for 24h clock.
    "HH:mm:ss"
    You get the text string by calling sdf.format(timeFromDb)
    Kaj

  • How do I get the text to flow throughout more then one page.

    Hello,
    I am currently using LiveCycke Designer to create a scholarship for my company. I created fields for the form and I would like to insert a text to describe the scholarship. When I insert the text, it doesn't flow onto the next page. I've tried creating a subform and clicking "flowed" and "allow page breaks within content". I also clicked auto-fit for the height, but it just makes a line. For the text box, I've clicked "Expand to fit on the height". It is also a dynamic XML Form. Is there anything else I should be doing?
    I could always send the file to someone to see if they can figure it out.
    Thank you,
    Natalie

    Thank you so much !
    but the link doesn't seem to work. It says that the URL is not in the correct format for an Acrobat.com document link.
    Natalie
    Date: Wed, 12 May 2010 07:53:12 -0600
    From: [email protected]
    To: [email protected]
    Subject: How do I get the text to flow throughout more then one page.
    Here is the corrected form..Even you you set the Subform type to "Flowed" to the subform where the Text box resides, you did not set the Page1 to Flowed (which is the key)..But when I make the Page1 type to "Flowed", all your fields above the Scholrship text boxes' Subform will go one below another.. To fix this, first I have select all the fields and wrap them into a subform and then set the Page1 to Flowed..
    https://acrobat.com/#d=XQ1yfV8fCk85M7sRLD*-gg
    Thanks
    Srini
    >

  • How can I get the "text" field from the actionEvent.getSource() ?

    I have some sample code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.ArrayList;
    public class JFrameTester{
         public static void main( String[] args ) {
              JFrame f = new JFrame("JFrame");
              f.setSize( 500, 500 );
              ArrayList < JButton > buttonsArr = new ArrayList < JButton > ();
              buttonsArr.add( new JButton( "first" ) );
              buttonsArr.add( new JButton( "second" ) );
              buttonsArr.add( new JButton( "third" ) );
              MyListener myListener = new MyListener();
              ( (JButton) buttonsArr.get( 0 ) ).addActionListener( myListener );
              ( (JButton) buttonsArr.get( 1 ) ).addActionListener( myListener );
              ( (JButton) buttonsArr.get( 2 ) ).addActionListener( myListener );
              JPanel panel = new JPanel();
              panel.add( buttonsArr.get( 0 ) );
              panel.add( buttonsArr.get( 1 ) );
              panel.add( buttonsArr.get( 2 ) );
              f.getContentPane().add( BorderLayout.CENTER, panel );
              f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              f.setVisible( true );
         public static class MyListener  implements ActionListener{
              public MyListener() {}
              public void actionPerformed( ActionEvent e ) {
                   System.out.println( "hi!! " + e.getSource() );
                   // I need to know a title of the button (which was clicked)...
    }The output of the code is something like this:
    hi! javax.swing.JButton[,140,5,60x25,alignmentX=0.0,alignmentY=0.5,
    border=javax.swing.plaf.BorderUIResource$CompoundBorderUIResource@1ebcda2d,
    flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,
    disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,
    right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,
    rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=first,defaultCapable=true]
    I need this: "first" (from this part: "text=first" of the output above).
    Does anyone know how can I get the "text" field from the e.getSource() ?

    System.out.println( "hi!! " + ( (JButton) e.getSource() ).getText() );I think the problem is solved..If your need is to know the text of the button, yes.
    In a real-world application, no.
    In a RW application, a typical need is merely to know the "logical role" of the button (i.e., the button that validates the form, regardless of whether its text is "OK" or "Save", "Go",...). Text tends to vary much more than the structure of the UI over time.
    In this case you can get the source's name (+getName()+), which will be the name that you've set to the button at UI construction time. Or you can compare the source for equality with either button ( +if evt.getSource()==okButton) {...}+ ).
    All in all, I think the best solution is: don't use the same ActionListener for more than one action (+i.e.+ don't add the same ActionListener to all your buttons, which leads to a big if-then-else series in your actionPerformed() ).
    Eventually, if you're listening to a single button's actions, whose text change over time (e.g. "pause"/"resume" in a VCR bar), I still think it's a bad idea to rely on the text of the button - instead, this text corresponds to a logical state (resp. playing/paused), it is more maintainable to base your logic on the state - which is more resilient to the evolutions of the UI (e.g. if you happen to use 2 toggle buttons instead of one single play/pause button).

  • In popup step how do I get the "text on the button" in the report rather than button index?

    (1)
    How do I configure the POPUP step in "SEQ MAIN.seq" to execute the second
    step (IS OUT PUT IS 20?) in "SEQ 1.seq" when "IS OUT PUT IS 20?" button
    hit and execute the third step (IS OUT PUT IS 30?) in "SEQ 1.seq" when "IS
    OUT PUT IS 30?" button hit.
    (2)
    In popup step how do I get the "text on the button" in the report rather than button index?
    File attached
    Attachments:
    test_stand.zip ‏32 KB

    The handle to the Step.Button1Label gets you the data, but there are several ways to get it into the actual report.
    The easiest is to use the reporttext.
    In a post expression, you can use something like
    Step.Result.ReportText = Evaluate("Step.Button" + Str(Step.Result.ButtonHit) +"Label")
    and then the default report generation will include it in the report. Otherwise, you need to get the text into the Resultlist by various means (check the user manual, or the TestStand II customisation course) and handle the report generation yourself inside of the appropriate sequence in the process model.
    Just my 2cents
    S.
    // it takes almost no time to rate an answer
    Attachments:
    IncludeButtonTextInReport2_0.seq ‏18 KB

  • How can I get the text value of an XML element  in MXML ?

    Hi,
    I have the following XML loaded into a variable of type XML :
    <properties>
         <comment>RIMpro Data Collector Configuration</comment>
         <entry key="server.pear.username"/>
         <entry key="server.apple.retry.times">5</entry>
         <entry key="rdc.proxy.host">http://192.168.1.2:8080</entry>
    /properties>
    I can easily get the key attribute displayed in a DataGridColumn by setting the dataProvider to my variable and the dataField to "@key".  But I do not know how to get the text value in a second column...  Is there a way or do I need to change my XML to something like this :
    <properties>
         <comment>RIMpro Data Collector Configuration</comment>
         <entry key="server.pear.username"/>
         <entry key="server.apple.retry.times" value="5"></entry>
         <entry key="rdc.proxy.host" value="http://192.168.1.2:8080"></entry>
    /properties>
    Many thanks in advance.
    Marc

    yes, you'd better modify your XML structure to fit the DataGrid internals.
    Since dataField pattern require each grid row item to have a named property to be displayed, otherwise you'll be forced to overcome this pattern using custom labelFunction for the particular column which will implement your custom actions on how to extract appropriate data for that column out of grid row item. It will be much more complicated than just rearranging your xml structure.

  • Unable to get the Text proerty of Range class

    Hi,
    I am using the Text property of Range class for excel template development using VSTO.While reloading the template i am getting the error "Unable to get the Text proerty of Range class".If i skip this line of code,i am getting similar kind of errors while accessing the properties of Range class(like Range.copy() ,Range.Locked, Range.EntireRow.Hidden).In all these cases i am getting the similar kind of error "unable to get the property of Range Class".
    Waiting for a quick response...
    Thanks in advance..

    Hi Besse,
    Actully, the error is coming when i try to populate datatable with the the range values in one of the sheet.
    I am using the below code.
    //"wsInteropMetadata"  is the sheet object.
    //"RangeName" is the range name in the sheet.
    rngConfig = wsInteropMetadata.get_Range("RangeName", Type.Missing);
    for (int iRow = 1; iRow <= iRowCnt; iRow++)
        dRNew = dTMetadataTable.NewRow();
        for (int iCol = 1; iCol <= iColCnt; iCol++)
          rngCell = (Excel.Range)rngConfig.Cells[iRow, iCol];
          dRNew[iCol - 1] = rngCell.Text.ToString();
       dTMetadataTable.Rows.Add(dRNew);
    In the first load of the template,this code is working fine.In the reload i am getting the error at "rngCell.Text".If i see in quickwatch,most of the properties of  "rngCell" object are throwing "System.Runtime.InteropServices.COMException".See the below exception information.
     Exception Information
     Exception Type: System.Runtime.InteropServices.COMException
    Message: Unable to get the Text property of the Range class
    Source: Microsoft Office Excel
    ErrorCode: -2146827284
    Thanks
    Krishna.

  • How to get the text present in JTextArea

    i am writing application for some system to be computerised and i am not getting how to get the text present in text area and set it into database...can anybody suggest me solution??

    You must have named the TextArea like
    JTextArea textArea;so, use the getText() method like
    String strTextAreaContents = textArea.getText();You can then use JDBC to connect to the database that you want and save your contents that is now in strTextAreaContents.
    -- Srikanth

  • How to get the text of the textArea ?

    Hi, expert
    i have created a new component com1,
    then i created a table view name 'result'.
    then i add a textarea by modifying the result.htm
    textArea id     = "TAMSG"
                     text   = "test......"
    then i add a button in the result.htm
    the method of the button is  'EH_ONSENDMSG'
    then i input some text into the textArea on the page.
    now, how can i get the text of the textArea in the method 'EH_ONSENDMSG' ?
    thanks.
    oliver.

    Hi,
    problem was solved.
    i put the text into a value node.
    <thtmlb:textArea id     = "TAMSG"
                     text   = "//TEXT/TEXT2"
                     encode = "TRUE"
                     width  = "100%" />
    method EH_ONSENDMSG.
      DATA lr_col_wrap      TYPE REF TO   cl_bsp_wd_collection_wrapper.
      DATA lr_query_values  TYPE REF TO   if_bol_bo_property_access.
      DATA lv_str_msg TYPE string.
      lr_col_wrap = me->typed_context->text->get_collection_wrapper( ).
      lr_query_values ?= lr_col_wrap->get_current( ).
      lv_str_msg = lr_query_values->get_property_as_string( iv_attr_name = 'TEXT2' ).
    endmethod.
    regards.
    oliver.

  • How to get the 'text' property value of a button in coding?

    Hi Experts,
    I'm using 10 buttons all are having common action('click'). when i click a button the 'text' value of the button should pass to a function.So the action is same but the passed value will be the 'text' value of the corresponding button.  I don't know how to get the 'text' property of a button in coding. Kindly help me to solve this problem.
    Thanks and Regards
    Basheer

    Hi,
    My event is like this.
    public void onActionclick(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
         String s =  ?  ; // should get the 'text' property of clicked button
         fillInput(s);     // function to be called
    The called function is,
    public void fillInput( java.lang.String id )
        String str=wdContext.currentContextElement().getNum();
        str = str + id;
        wdContext.currentContextElement().setNum(str);
    How can i get the 'text' property value of the corresponding button. Click action should be common to all buttons.
    Thanks and Regards,
    Basheer

  • G'day, i am trying to type into an adobe document using the typewriter function. However everytime after i type the text vanishes. It is almost as if the text is white and vanishes into the background. However this is not the case as the works are not vis

    G'day,
    I need some help, i am trying to type into an adobe document using the typewriter function.
    However every time after i type the text vanishes. It is almost as if the text is white and vanishes into the background.
    This is not the case as the works are not visible regardless of the background color.
    The text box remains available and can be edited if clicked on, also if i double click on it the typed words become visible and editable, however once i close the box i cannot see them on the screen.
    I would appreciate any help i can get, i cant seem to do anything using properties or view.
    Thanks 
    Tiernan

    Hi Sara,
    See response to your questions below:
    1.     Are you running into this issue in a specific PDF, or in all of them?
    A.     All of them
    2.     What version of Acrobat are you using (and, are you on Mac OS or Windows?).
    A.     Using Acrobat 10.0\Acrobat on Windows
    3.     If you look at the text properties on the Tools panel (under Format), what color is the text swatch?
    A.     Test swatch for the text is black
    4.     What happens if you change the text color?
    A.     Nothing.
    I look forward to hearing back from you.

  • Get the texts written in the report program

    Hi
    Is there any way(any table /FM) to get  the texts written in the report program .

    Hi
    check this code...
    DATA: itab TYPE string WITH HEADER LINE.
    PARAMETERS: tcode TYPE tstc-tcode.
    PARAMETERS: prog TYPE rs38m-programm.
    IF tcode IS NOT INITIAL.
      SELECT SINGLE pgmna FROM tstc INTO prog WHERE tcode = tcode.
    ENDIF.
    READ REPORT prog INTO itab.
      INSERT REPORT 'YDEV_TEST' FROM itab.
      GENERATE REPORT 'YDEV_TEST'.
      SUBMIT ydev_test VIA SELECTION-SCREEN.
      DELETE REPORT 'YDEV_TEST'.

Maybe you are looking for