Non-String classes in List-type Controls

Got a Java "idiom" question for you experienced Swing developers: List-based controls take any class as items and call its toString method to populate the display. However, most classes that I run into don't override toString in any way that would work in a user display. I find that I'm constantly having to create a new class for each list-based control just to override the toString method, which is repetitive, tedious and seems like a high clutter-to-payoff ratio. My question is, is this the preferred approach? Are there better idioms? TIA.
-Steve

Thanks. That works pretty well, except getListCellRendererComponent doesn't give you an easy way to retrieve the index of the item you are rendering (the index parameter returns -1 for the display area of the combobox). Your item class has to have some method that returns the label, even if it is not toString(). Otherwise you have to spin through the ListModel manually testing for equality to the value parameter to find the index. Kludge.

Similar Messages

  • Question about the String class

    Did I understood the JLS/Javadoc properly if I say that the String class has got an internal pool of String objects (therefore I expect this pool to be stored in some sort of static variable)?
    Looking at the intern() method in the String class, this is declared as native, which make me think the whole pooling thing is managed internally by the JVM.
    Does this mean that, if there is only a String class per JVM and String literals (or better Strings that are values of constant expressions) are pooled in the String class, the more String constants are around the bigger the String class object becomes?

    Did I understood the JLS/Javadoc properly if I say
    that the String class has got an internal pool of
    String objects (therefore I expect this pool to be
    stored in some sort of static variable)?Yes.
    Looking at the intern() method in the String class,
    this is declared as native, which make me think the
    whole pooling thing is managed internally by the JVM.The intern() method is implemented in some programming language. If you happen to have a Java runtime where it is written as a native method, it is probably implemented in C or C++. Not a terribly important detail.
    Does this mean that, if there is only a String class
    per JVM and String literals (or better Strings that
    are values of constant expressions) are pooled in the
    String class, the more String constants are around
    the bigger the String class object becomes?The String.class object (of type java.lang.Class) as such doesn't "grow", but some memory structure somewhere will contain interned String literals. Probably a hash table of some sort. Yes indeed: if you have String literals in your program, those literals are stored in the computer's memory during runtime so that they can be accessed by the executable program code.

  • Statements like 'List String .class' cause error.

    Consider the following simple code:
        Class<List<String>> cl;
        cl=List<String>.class;The first line is valid but the second one causes the "illegal start of expression" error.
    That's rather strange: the type
    Class<List<String>>is valid itself, but variables of that type cannot be assigned via the ".class" expression.
    Is this a bug or I am missing something?
    Thanks.

    Java generics aren't C++ templates; they don't cause new classes to be created based on parameter type.
    What this means is that for types...
    List<String> stringList = new ArrayList<String>();
    List<Number> numberList = new ArrayList<Number>();...the class of those lists is, in both cases, java.util.ArrayList...
    string.getClass().equals(ArrayList.class);
    numberList.getClass().equals(ArrayList.class);Neither class ArrayList<String> nor class ArrayList<Number> exist, because such generics information is wiped out at runtime. That's why an expression like...
    ArrayList<Number>.class...is illegal.

  • What is inserting the following code onto pages " div id="bikatoc" style="display: none;" a class="control" Close /a div class="toc" ul li class="toc-h2

    I am doing web development and when working with the wordpress dashboard tiny mce, each time I hit the update button the following piece of code is inserted into the page I am working on.
    <pre><nowiki><div id="bikatoc" style="display: none;"><a class="control">Close</a>
    <div class="toc">
    <ul>
    <li class="toc-h2"><a href="#toc0">Just for the Health of it</a></li>
    <li class="toc-h2"><a href="#toc1">Wild Yukon River Salmon</a></li>
    </ul>
    </div>
    </div>
    </nowiki></pre>
    Something is scanning the h1-h6 tags and creating a table of contents and inserting it into the page. This also happens when I use firebug on other random pages while using firefox.
    I have tried several other browsers to determine if this is a wordpress issue, but this only happens in firefox. It also only happens when I make changes with firebug in firefox. Using firebug lite in chrome did not cause this problem.
    I have been looking all over to figure out what is going on and why the is happening. It is making development near impossible and is forcing me to use a different browser (which I don't enjoy at all)
    Any help you can give me would be wonderful.
    Thank you for your help

    Is it always hidden with display:none?
    One standard diagnostic step is to try Firefox's Safe Mode to see whether it is caused by a custom setting or add-on.
    First, I recommend backing up your Firefox settings in case something goes wrong. See [https://support.mozilla.com/en-US/kb/Backing+up+your+information Backing up your information]. (You can copy your entire Firefox profile folder somewhere outside of the Mozilla folder.)
    Next, restart Firefox in [http://support.mozilla.com/kb/Safe+Mode Safe Mode] using
    Help > Restart with Add-ons Disabled
    In the Safe Mode dialog, do not check any boxes, just click "Continue in Safe Mode."
    If the inserts stop, this points to an add-on as the problem. Figuring out which one it is would be the next step. (If the TOC is always hidden, perhaps it is something SEO-related.)

  • To differenciate string and list types in Xpress language

    Hi! I have a question in Xpress language:
    I'd like to know how to differentiate between string and list types. For example, *<s>orange</s>* and *<list><s>orange<s></list>*
    How does it know Xpress language what is it string or list?
    Thanks a lot.
    P.D. Excuse for the strike text, I don't know why it shows striked test.

    Try this:
    <instanceof name='List'>
    <ref>orange</ref>
    </instanceof>
    Edited by: Mindie on Mar 28, 2008 8:12 AM
    Edited by: Mindie on Mar 28, 2008 8:13 AM
    Edited by: Mindie on Mar 28, 2008 8:13 AM
    Edited by: Mindie on Mar 28, 2008 8:13 AM

  • The default value as "None" for the report filter which is Value List type?

    Hello,
    I want to know is it possible to make the default value as "None" for the report filter which is Value List data type?
    For example:The Project Classification Value List value type which have many value like "Supplier Rationalization" "Category Sourcing" "Contract Regegotiation" etc, and the value "Supplier Rationalization" is in the frist positon in the value list. When i use "Project Classification " as a report filter, the value "Supplier Rationalization" displayed as default value. And in the value list box in report filter of Project Classification , there is a value "None" which should be added automatically by system. So i manually filled the default value with "None" in Filter Prompt screen, but it does not work. After i display the report ,the Project Classification filter still use the ""Supplier Rationalization" as the default value.
    My current ESO version is 5.1. I tried other ESO version like 5.15, if i manaully give a default value "None" in Filter Prompt screen for filter Project Classification, then the default value is "None". It works well.
    Does anybody know if it's possible to do the same thing in ESO 5.1?
    Thanks & Regards,
    David
    Edited by: David Gao on Aug 11, 2010 4:06 AM

    Hi David -
    This is possible, but the technique is not too obvious...
    To make "None" be the default choice for a query definition filter parameter of type value list type, you need to set the default value of the filter parameter to the following:
    <internal id of value list type>:616:NULL
    For example, I believe you will see that the internal id of the Project Classification value list type is 51, so the default value of the filter parameter would be:
    51:616:NULL
    I hope this helps.
    Regards,
    Rob

  • Alv using class In list format

    Hi,
    I am using a method set_table_for_first_display in class cl_gui_alv_grid to display ALV. but by default the output appears in grid format, I want to change the output in LIST format.
    What can I do to change the output in list format.
    Kind Regards,
    Abhishek.

    try this.... this is an example code.... don't use set_table_for_first_display rather use CL_SALV_TABLE and execute the below code
    *& Report  ZAMIT_TEST
    REPORT  zamit_test  MESSAGE-ID z_zzz_ca_messages.
    * constants for icons
    TYPE-POOLS: icon, col.
    * type for internal table
    TYPES: BEGIN OF x_sflight.
    *       selfld TYPE char1.
            INCLUDE STRUCTURE sflight.
    TYPES: seatsfree TYPE sflight-seatsocc,
           usage TYPE n,                    " exception
           icon_future TYPE icon-id,        " icon for future / past
           line_counter TYPE i,             " line counter
           it_colors TYPE lvc_t_scol, " internal tab for cell color info
    END OF x_sflight.
    * Internal table
    DATA: i_sflight  TYPE STANDARD TABLE OF x_sflight,
          wa_sflight TYPE x_sflight,
          wa_colors  TYPE lvc_s_scol,
          list_display TYPE sap_bool,
          vref_cont    TYPE REF TO cl_gui_custom_container,
          vref_alv     TYPE REF TO cl_salv_table,      " ALV instance
          oref_error   TYPE REF TO cx_salv_error,      " Error instance
          l_text_alv_e TYPE string,
          ok_code      TYPE syucomm.
    SELECT-OPTIONS: so_car FOR wa_sflight-carrid MEMORY ID car,
                    so_con FOR wa_sflight-connid.
    SELECTION-SCREEN SKIP 1.
    SELECTION-SCREEN BEGIN OF BLOCK alv WITH FRAME TITLE text-alv.
    PARAMETERS: pa_full RADIOBUTTON GROUP alvd DEFAULT 'X',
                pa_cont RADIOBUTTON GROUP alvd,
                pa_list RADIOBUTTON GROUP alvd.
    SELECTION-SCREEN END OF BLOCK alv.
    PARAMETERS: p_layout TYPE slis_vari.
    *       CLASS lcl_handler DEFINITION
    CLASS lcl_handler DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
        on_added_function FOR EVENT added_function OF cl_salv_events_table
                IMPORTING e_salv_function, " type salv_de_function
        on_double_click FOR EVENT double_click OF cl_salv_events_table
                IMPORTING row,   " type salv_de_row = int4
        on_link_click FOR EVENT link_click OF cl_salv_events_table
                IMPORTING row    " type salv_de_row = int4
                          column." type salv_de_column = char(30)
    ENDCLASS. "lcl_handler definition
    * CLASS lcl_handler IMPLEMENTATION
    CLASS lcl_handler IMPLEMENTATION.
      METHOD on_added_function.
        DATA: l_oref_columns TYPE REF TO cl_salv_columns_table,
              l_oref_column  TYPE REF TO cl_salv_column_table,
              l_oref_column1 TYPE REF TO cl_salv_column,
              l_except1      TYPE REF TO cx_salv_not_found,   "Exception
              l_text1        TYPE string,                     "Exception msg
              l_lvc_s_colo TYPE lvc_s_colo.
        CASE e_salv_function.
          WHEN 'REORDER'.
    * get the COLUMNS object
            l_oref_columns = vref_alv->get_columns( ).
    * positions: (MANDT column + 3 key colums)
            l_oref_columns->set_column_position( columnname = 'SEATSOCC'
                                                 position = 5 ).
            l_oref_columns->set_column_position( columnname = 'SEATSOCC_B'
                                                 position = 6 ).
            l_oref_columns->set_column_position( columnname = 'SEATSOCC_F'
                                                 position = 7 ).
    *       prepare color info
    *       column SEATSOCC
            TRY.
                CALL METHOD l_oref_columns->get_column
                  EXPORTING
                    columnname = 'SEATSOCC'
                  RECEIVING
                    value      = l_oref_column1.
              CATCH cx_salv_not_found INTO l_except1.
                l_text1 = l_except1->get_text( ).
                MESSAGE i000 WITH l_text1.
                LEAVE LIST-PROCESSING.
            ENDTRY.
            l_oref_column ?= l_oref_column1.
            l_oref_column->set_color( value = l_lvc_s_colo ).
    *       column SEATSOCC_B
            TRY.
                CALL METHOD l_oref_columns->get_column
                  EXPORTING
                    columnname = 'SEATSOCC_B'
                  RECEIVING
                    value      = l_oref_column1.
              CATCH cx_salv_not_found INTO l_except1.
                l_text1 = l_except1->get_text( ).
                MESSAGE i000 WITH l_text1.
                LEAVE LIST-PROCESSING.
            ENDTRY.
            l_oref_column ?= l_oref_column1.
            l_oref_column->set_color( value = l_lvc_s_colo ).
    *       column SEATSOCC_F
            TRY.
                CALL METHOD l_oref_columns->get_column
                  EXPORTING
                    columnname = 'SEATSOCC_F'
                  RECEIVING
                    value      = l_oref_column1.
              CATCH cx_salv_not_found INTO l_except1.
                l_text1 = l_except1->get_text( ).
                MESSAGE i000 WITH l_text1.
                LEAVE LIST-PROCESSING.
            ENDTRY.
            l_oref_column ?= l_oref_column1.
            l_oref_column->set_color( value = l_lvc_s_colo ).
        ENDCASE.
      ENDMETHOD. "on_added_function
      METHOD on_double_click.
        DATA: message_text(70),
              lc_seatsfree_e(10),
              lc_seatsfree_b(10),
              lc_seatsfree_f(10).
        READ TABLE i_sflight INTO wa_sflight INDEX row.
        CHECK sy-subrc EQ 0.
        lc_seatsfree_e = wa_sflight-seatsmax - wa_sflight-seatsocc.
        lc_seatsfree_b = wa_sflight-seatsmax_b - wa_sflight-seatsocc_b.
        lc_seatsfree_f = wa_sflight-seatsmax_f - wa_sflight-seatsocc_f.
        CONCATENATE 'FREE SEATS:'(frs) 'ECONOMY:'(eco) lc_seatsfree_e
        'BUSINESS'(bus) lc_seatsfree_b 'FIRST'(fst) lc_seatsfree_f
                        INTO message_text SEPARATED BY space.
        MESSAGE message_text TYPE 'I'.
      ENDMETHOD. "on_double_click
      METHOD on_link_click.
        DATA: lc_carrname TYPE scarr-carrname,
        lc_currcode TYPE scarr-currcode,
        message_text(70).
        READ TABLE i_sflight INTO wa_sflight INDEX row.
        CHECK sy-subrc EQ 0.
        CASE column.
          WHEN 'CARRID'.
            SELECT SINGLE carrname currcode
            INTO (lc_carrname, lc_currcode)
            FROM scarr
            WHERE carrid = wa_sflight-carrid.
            IF sy-subrc EQ 0.
              CONCATENATE 'AIRLINE:'(air) wa_sflight-carrid
              'NAME:'(nme) lc_carrname
              'CURRENCY:' lc_currcode
              INTO message_text
              SEPARATED BY space.
              MESSAGE message_text TYPE 'I'.
            ENDIF.
          WHEN 'SELFLD'.
            MESSAGE i000 with 'Checkbox Clicked'.
        ENDCASE.
      ENDMETHOD. "on_link_click
    ENDCLASS. "lcl_handler IMPLEMENTATION
    START-OF-SELECTION.
    * retrieve data into internal table
      SELECT * FROM sflight
      INTO CORRESPONDING FIELDS OF TABLE i_sflight
      WHERE carrid IN so_car
      AND connid IN so_con.
    END-OF-SELECTION.
    * fill additional data fields
      LOOP AT i_sflight INTO wa_sflight.
    * seats free
        wa_sflight-seatsfree =
        wa_sflight-seatsmax + wa_sflight-seatsmax_b
        + wa_sflight-seatsmax_f
        - wa_sflight-seatsocc - wa_sflight-seatsocc_b
        - wa_sflight-seatsocc_f.
    * usage (exception light)
        IF wa_sflight-seatsfree = 0.
          wa_sflight-usage = '1'.
        ELSEIF wa_sflight-seatsfree <= 20.
          wa_sflight-usage = '2'.
        ELSE.
          wa_sflight-usage = '3'.
        ENDIF.
    * icon "in the future/not in the future"
        IF wa_sflight-fldate > sy-datum.
          wa_sflight-icon_future = icon_positive.
        ELSE.
          wa_sflight-icon_future = icon_negative.
        ENDIF.
    * cell colors
    * single cell if planetype is 747-400
        IF wa_sflight-planetype = '747-400'.
          CLEAR wa_colors.
          wa_colors-fname = 'PLANETYPE'.
          wa_colors-color-col = col_positive.
          wa_colors-color-int = 1.
          APPEND wa_colors TO wa_sflight-it_colors.
        ENDIF.
    * whole line if seatsfree gt 200
        IF wa_sflight-seatsfree >= 200.
          CLEAR wa_colors.
          wa_colors-color-col = col_heading.
          wa_colors-color-int = 1.
          APPEND wa_colors TO wa_sflight-it_colors.
        ENDIF.
        MODIFY i_sflight
        FROM wa_sflight
             TRANSPORTING
        seatsfree
        usage
        icon_future
        it_colors.
      ENDLOOP.
      CASE 'X'.
        WHEN pa_full OR pa_list.
          IF pa_list IS NOT INITIAL.
            list_display = if_salv_c_bool_sap=>true.
          ELSE.
            list_display = if_salv_c_bool_sap=>false.
          ENDIF.
          TRY.
              CALL METHOD cl_salv_table=>factory
                EXPORTING
                  list_display = list_display
                IMPORTING
                  r_salv_table = vref_alv
                CHANGING
                  t_table      = i_sflight.
            CATCH cx_salv_msg INTO oref_error.
              l_text_alv_e = oref_error->get_text( ).
              MESSAGE i000 WITH l_text_alv_e.
              LEAVE LIST-PROCESSING.
          ENDTRY.
    * define settings
          PERFORM define_settings USING vref_alv.
    * display ALV
          vref_alv->display( ).
        WHEN pa_cont.
          CALL SCREEN 100.
      ENDCASE.
    *&      Form  define_settings
    *       text
    *      -->P_ALV      ALV object
    FORM define_settings USING p_alv TYPE REF TO cl_salv_table.
      PERFORM: sub_set_display    USING p_alv,
               sub_set_columns    USING p_alv,
               sub_set_sorts      USING p_alv,
               sub_set_aggregs    USING p_alv,
               sub_set_selections USING p_alv,
               sub_set_layout     USING p_alv,
               sub_set_functions  USING p_alv,
               sub_set_events     USING p_alv,
               sub_set_header     USING p_alv.
    ENDFORM. " define_settings
    *& Form sub_set_display
    * set general display attributs
    * -->P_ALV ALV object
    FORM sub_set_display USING p_alv TYPE REF TO cl_salv_table.
      DATA: lr_display TYPE REF TO cl_salv_display_settings,
            l_title TYPE lvc_title.
    * get display settings object
      lr_display = p_alv->get_display_settings( ).
    * set header
      l_title = text-ttl.
      lr_display->set_list_header( value = text-ttl ).
    * set horizontal lines off
      lr_display->set_horizontal_lines( value = ' '  ).
    * set striped pattern
      lr_display->set_striped_pattern( value = 'X' ).
    ENDFORM. " sub_set_display
    *&      Form  sub_set_columns
    *       text
    *      -->P_ALV      text
    FORM sub_set_columns USING p_alv TYPE REF TO cl_salv_table.
      DATA: l_oref_columns TYPE REF TO cl_salv_columns_table,
            l_oref_column  TYPE REF TO cl_salv_column_table,
            l_oref_column1 TYPE REF TO cl_salv_column,
            l_except1      TYPE REF TO cx_salv_not_found,   "Exception
            l_except2      TYPE REF TO cx_salv_data_error,  "Exception
            l_text1        TYPE string,                     "Exception msg
            l_scrtext_s    TYPE scrtext_s,
            l_scrtext_m    TYPE scrtext_m,
            l_scrtext_l    TYPE scrtext_l,
            l_lvc_tip      TYPE lvc_tip,     " for tooltip
            l_pos          TYPE i,           " column position
            l_lvc_s_colo   TYPE lvc_s_colo.  " column color
      l_oref_columns = p_alv->get_columns( ).   " get columns object
    * set exception column
      TRY.
          CALL METHOD l_oref_columns->set_exception_column
            EXPORTING
              value = 'USAGE'.
        CATCH cx_salv_data_error INTO l_except2.
          l_text1 = l_except2->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
    * set count column
      TRY.
          CALL METHOD l_oref_columns->set_count_column
            EXPORTING
              value = 'LINE_COUNTER'.
        CATCH cx_salv_data_error INTO l_except2.
          l_text1 = l_except2->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
    * set cell colors / line colors column
      TRY.
          CALL METHOD l_oref_columns->set_color_column
            EXPORTING
              value = 'IT_COLORS'.
        CATCH cx_salv_data_error INTO l_except2.
          l_text1 = l_except2->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
    * column ICON_FUTURE
      TRY.
          CALL METHOD l_oref_columns->get_column
            EXPORTING
              columnname = 'ICON_FUTURE'
            RECEIVING
              value      = l_oref_column1.
        CATCH cx_salv_not_found INTO l_except1.
          l_text1 = l_except1->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
      l_oref_column ?= l_oref_column1.
      l_oref_column->set_icon( ).
      l_scrtext_s = text-fut.
      l_oref_column->set_short_text( value = l_scrtext_s ).
      l_oref_column->set_row( value = 2 ).
    * Column SEATSFREE
      TRY.
          CALL METHOD l_oref_columns->get_column
            EXPORTING
              columnname = 'SEATSFREE'
            RECEIVING
              value      = l_oref_column1.
        CATCH cx_salv_not_found INTO l_except1.
          l_text1 = l_except1->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
      l_oref_column ?= l_oref_column1.
    * set color to COL_GROUP
      l_lvc_s_colo-col = col_group.
      l_lvc_s_colo-int = 1.
      l_oref_column->set_color( value = l_lvc_s_colo ).
    ** Column SELFLD
    *  TRY.
    *      CALL METHOD l_oref_columns->get_column
    *        EXPORTING
    *          columnname = 'SELFLD'
    *        RECEIVING
    *          value      = l_oref_column1.
    *    CATCH cx_salv_not_found INTO l_except1.
    *      l_text1 = l_except1->get_text( ).
    *      MESSAGE i000 WITH l_text1.
    *      LEAVE LIST-PROCESSING.
    *  ENDTRY.
    *  l_oref_column ?= l_oref_column1.
    ** set color to COL_GROUP
    *  if pa_list = 'X'.
    *  l_oref_column->set_cell_type( value =
    *                               if_salv_c_cell_type=>CHECKBOX ).
    *  ELSEIF pa_full = 'X'.
    *    l_oref_column->set_cell_type( value =
    *                               if_salv_c_cell_type=>CHECKBOX_HOTSPOT ).
    *  endif.
    ENDFORM.                    "sub_set_columns
    *& Form sub_set_sorts
    * -->P_ALV text
    FORM sub_set_sorts USING p_alv TYPE REF TO cl_salv_table.
      DATA: l_oref_sorts TYPE REF TO cl_salv_sorts,
            l_except1      TYPE REF TO cx_salv_not_found,   "Exception
            l_except2      TYPE REF TO cx_salv_existing,    "Exception
            l_except3      TYPE REF TO cx_salv_data_error,  "Exception
            l_text1        TYPE string.                     "Exception msg
    * get the SORTS object
      l_oref_sorts = p_alv->get_sorts( ).
    * add sorts
      TRY.
          CALL METHOD l_oref_sorts->add_sort
            EXPORTING
              columnname = 'CARRID'
              position   = 1.
        CATCH cx_salv_not_found INTO l_except1.
          l_text1 = l_except1->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_existing  INTO l_except2.
          l_text1 = l_except2->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_data_error INTO l_except3.
          l_text1 = l_except3->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
      TRY.
          CALL METHOD l_oref_sorts->add_sort
            EXPORTING
              columnname = 'CONNID'
              position   = 2
              subtotal   = if_salv_c_bool_sap=>true.
        CATCH cx_salv_not_found INTO l_except1.
          l_text1 = l_except1->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_existing  INTO l_except2.
          l_text1 = l_except2->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_data_error INTO l_except3.
          l_text1 = l_except3->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
      TRY.
          CALL METHOD l_oref_sorts->add_sort
            EXPORTING
              columnname = 'FLDATE'
              position   = 3.
        CATCH cx_salv_not_found INTO l_except1.
          l_text1 = l_except1->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_existing  INTO l_except2.
          l_text1 = l_except2->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_data_error INTO l_except3.
          l_text1 = l_except3->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
    ENDFORM. " sub_set_sorts
    *& Form sub_set_aggregs
    * -->P_ALV text
    FORM sub_set_aggregs USING p_alv TYPE REF TO cl_salv_table.
      DATA: l_oref_aggregs TYPE REF TO cl_salv_aggregations,
            l_except1      TYPE REF TO cx_salv_data_error,  "Exception
            l_except2      TYPE REF TO cx_salv_not_found,   "Exception
            l_except3      TYPE REF TO cx_salv_existing,    "Exception
            l_text1        TYPE string.                     "Exception msg
      l_oref_aggregs = p_alv->get_aggregations( ).
      TRY.
          CALL METHOD l_oref_aggregs->add_aggregation
            EXPORTING
              columnname  = 'SEATSFREE'
              aggregation = if_salv_c_aggregation=>total.
        CATCH cx_salv_data_error INTO l_except1.
          l_text1 = l_except1->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_not_found  INTO l_except2.
          l_text1 = l_except2->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
        CATCH cx_salv_existing   INTO l_except3.
          l_text1 = l_except3->get_text( ).
          MESSAGE i000 WITH l_text1.
          LEAVE LIST-PROCESSING.
      ENDTRY.
    ENDFORM. " sub_set_aggregs
    *& Form sub_set_selections
    * -->P_ALV text
    FORM sub_set_selections USING p_alv TYPE REF TO cl_salv_table.
      DATA: lr_selections TYPE REF TO cl_salv_selections.
    * get the SELECTIONS object
      lr_selections = p_alv->get_selections( ).
    * set the selection mode
      lr_selections->set_selection_mode(
                     value = if_salv_c_selection_mode=>cell ).
    ENDFORM. " sub_set_selections
    *& Form sub_set_layout
    * -->P_ALV text
    FORM sub_set_layout USING p_alv TYPE REF TO cl_salv_table.
      DATA: lr_layout TYPE REF TO cl_salv_layout,
      ls_key TYPE salv_s_layout_key.
    * get the LAYOUT object
      lr_layout = p_alv->get_layout( ).
    * set the layout key
      ls_key-report = sy-cprog.
      lr_layout->set_key( value = ls_key ).
    * set save restriction
    * (restriction "none" is intended,
    * so we may use the default)
      lr_layout->set_save_restriction(
    * VALUE = IF_SALV_C_LAYOUT=>RESTRICT_NONE
    * allow setting a default layout
      lr_layout->set_default( value = 'X' ).
    * set initial layout
      lr_layout->set_initial_layout( value = p_layout ).
    ENDFORM. " sub_set_layout
    *& Form sub_set_functions
    * -->P_ALV text
    FORM sub_set_functions USING p_alv TYPE REF TO cl_salv_table.
      DATA: lr_functions TYPE REF TO cl_salv_functions_list,
            l_except1    TYPE REF TO cx_salv_existing,
            l_except2    TYPE REF TO cx_salv_wrong_call,
            l_text1      TYPE string,
    * help variables for method call ADD_FUNCTION
            l_icon       TYPE string,
            l_text       TYPE string,
            l_tooltip    TYPE string.
    IF pa_full = 'X' or pa_list = 'X'.
      p_alv->set_screen_status( pfstatus = 'SALV_TABLE_STANDARD'
                                report = sy-repid
                           set_functions = p_alv->c_functions_all ).
    ENDIF.
    * get the FUNCTIONS object
      lr_functions = p_alv->get_functions( ).
    * offer all generic functions
      lr_functions->set_all( value = if_salv_c_bool_sap=>true ).
    * subtract average
      lr_functions->set_aggregation_average(
                        value = if_salv_c_bool_sap=>false ).
    * subtract all export functions
      lr_functions->set_group_export(
                        value = if_salv_c_bool_sap=>false ).
    * enable exort to local file
      lr_functions->set_export_localfile(
                        value = if_salv_c_bool_sap=>true ).
    * subtract transfer to lotus
      lr_functions->set_view_lotus(
                        value = if_salv_c_bool_sap=>false ).
    * customer defined function:
    * display occupied seats columns most left
    * and highlight them
    *  IF pa_cont = 'X'.
    *    l_icon = icon_insert_row.
    *    l_text = text-tot.
    *    l_tooltip = text-ttt.
    *    TRY.
    *        CALL METHOD lr_functions->add_function
    *          EXPORTING
    *            name     = 'REORDER'
    *            icon     = l_icon
    *            text     = l_text
    *            tooltip  = l_tooltip
    *     position = if_salv_c_function_position=>right_of_salv_functions.
    *      CATCH cx_salv_existing   INTO l_except1.
    *        l_text1 = l_except1->get_text( ).
    *        MESSAGE i000 WITH l_text1.
    *        LEAVE LIST-PROCESSING.
    *      CATCH cx_salv_wrong_call INTO l_except2.
    *        l_text1 = l_except2->get_text( ).
    *        MESSAGE i000 WITH l_text1.
    *        LEAVE LIST-PROCESSING.
    *    ENDTRY.
    *  ENDIF.
    ENDFORM. " sub_set_functions
    *& Form sub_set_events
    * text
    * -->P_ALV text
    FORM sub_set_events USING p_alv TYPE REF TO cl_salv_table.
      DATA: lr_event TYPE REF TO cl_salv_events_table.
    * get the EVENT object
      lr_event = p_alv->get_event( ).
      SET HANDLER :
      lcl_handler=>on_added_function FOR lr_event,
      lcl_handler=>on_double_click   FOR lr_event,
      lcl_handler=>on_link_click     FOR lr_event.
    ENDFORM. " sub_set_events
    *& Form sub_set_header
    * -->P_ALV text
    FORM sub_set_header
    USING p_alv TYPE REF TO cl_salv_table.
      DATA: lr_grid TYPE REF TO cl_salv_form_layout_grid.
    * 1st step: create the grid object
      CREATE OBJECT lr_grid.
    * 2nd step: add some text items
      lr_grid->create_header_information( row = 1  column = 1
                             text = 'Flight List Grp ##'(fll) ).
      lr_grid->create_text( row = 2  column = 1
                             text = 'Please check utilization'(uti) ).
    * 3rd step: declare grid as header of list
      p_alv->set_top_of_list( value = lr_grid ).
    ENDFORM. " sub_set_header
    *& Module STATUS_0100 OUTPUT
    * text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SALV_TABLE_STANDARD'.
      SET TITLEBAR 'T100'.
    ENDMODULE. " STATUS_0100 OUTPUT
    *& Module create_control OUTPUT
    * text
    MODULE create_control OUTPUT.
      IF vref_cont IS NOT BOUND.
    * create container control
    * and link it to the dynpro
        CREATE OBJECT vref_cont
        EXPORTING
          container_name = 'MY_CONTAINER'
        EXCEPTIONS
          OTHERS = 1.
        IF sy-subrc <> 0.
          MESSAGE e000 WITH 'Error when creating the container object'.
        ENDIF.
    * create ALV and
    * link it to the container control
        TRY.
            cl_salv_table=>factory(
            EXPORTING
              r_container = vref_cont
            IMPORTING
              r_salv_table = vref_alv
            CHANGING
              t_table = i_sflight ).
          CATCH cx_salv_msg INTO oref_error.
            l_text_alv_e = oref_error->get_text( ).
            MESSAGE i000 WITH l_text_alv_e.
            LEAVE LIST-PROCESSING.
        ENDTRY.
    * display ALV
        vref_alv->display( ).
      ENDIF.
    ENDMODULE. " create_control OUTPUT
    *& Module USER_COMMAND_0100 INPUT
    * text
    MODULE user_command_0100 INPUT.
      CASE sy-ucomm.
        WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
          SET SCREEN 0.
      ENDCASE.
    ENDMODULE. " USER_COMMAND_0100 INPUT
    *&      Module  exit  INPUT
    *       text
    MODULE exit INPUT.
      SET SCREEN 0.
    ENDMODULE.                 " exit  INPUT

  • Non-servlet class in servlet program

    hi,
    I declare a non-servlet class which is defined by myself in a servlet class. I passed the complie but got an runtime error said NoClassDefFoundError. Does anyone can help me? Thanks.
    The following is my code.
    //get the search string from web form
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.net.*;
    import java.util.*;
    public class SearchEngines extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {   
    String searchString = (String) request.getParameter("searchString");
         String searchType = (String) request.getParameter("searchType");
         Date date = new java.util.Date();
         response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    Vector doc_retrieved = new Vector();
    BooleanSearch bs = new BooleanSearch();
    doc_retrieved=bs.beginSearch(searchString, searchType);
    out.println("<HTML><HEAD><TITLE>Hello Client!</TITLE>" +
                   "</HEAD><BODY>Hello Client! " + doc_retrieved.size() + " documents have been found.</BODY></HTML>");
    out.close();
    response.sendError(response.SC_NOT_FOUND,
    "No recognized search engine specified.");
    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    // a search engine implements the boolean search
    import java.io.*;
    import java.util.*;
    import au.com.pharos.gdbm.GdbmFile;
    import au.com.pharos.gdbm.GdbmException;
    import au.com.pharos.packing.StringPacking;
    import IRUtilities.Porter;
    public class BooleanSearch{
         BooleanSearch(){;}
         public Vector beginSearch(String searchString, String searchType){
              Vector query_vector = queryVector(searchString);
              Vector doc_retrieved = new Vector();
              if (searchType.equals("AND"))
                   doc_retrieved = andSearch(query_vector);
              else
                   doc_retrieved = orSearch(query_vector);
              return doc_retrieved;
         private Vector queryVector(String query){
         Vector query_vector = new Vector();
              try{
                   GdbmFile dbTerm = new GdbmFile("Term.gdbm", GdbmFile.READER);
              dbTerm.setKeyPacking(new StringPacking());
              dbTerm.setValuePacking(new StringPacking());
              query = query.toLowerCase();
              StringTokenizer st = new StringTokenizer(query);
              String word = "";
              String term_id = "";
              while (st.hasMoreTokens()){
                   word = st.nextToken();
                   if (!search(word)){
                        word = Stemming(word);
                        if (dbTerm.exists(word)){
                   //          System.out.println(word);
                             term_id = (String) dbTerm.fetch(word);
                             query_vector.add(term_id);
              catch(GdbmException e){
                   System.out.println(e.getMessage());
              return query_vector;
         private Vector orSearch(Vector query_vector){
              Vector doc_retrieved = new Vector();
              try{
                   GdbmFile dbVector = new GdbmFile("Vector.gdbm", GdbmFile.READER);
                   dbVector.setKeyPacking(new StringPacking());
                   dbVector.setValuePacking(new StringPacking());
                   int doc_num = dbVector.size();
                   String doc_id = "";
                   String temp = "";
                   for (int i = 1; i <= doc_num; i++){
                        boolean found = false;
                        doc_id = String.valueOf(i);
                        temp = (String) dbVector.fetch(doc_id);
                        StringTokenizer st = new StringTokenizer(temp);
                        while (st.hasMoreTokens() && !found){
                             temp = st.nextToken();
                             StringTokenizer st1 = new StringTokenizer(temp, ",");
                             String term = st1.nextToken();
                             if (query_vector.contains(term)){
                                  doc_retrieved.add(doc_id);
                                  found = true;
              catch(GdbmException e){
                   System.out.println(e.getMessage());
              return doc_retrieved;
         private Vector andSearch(Vector query_vector){
              Vector doc_retrieved = new Vector();
              try{
                   GdbmFile dbVector = new GdbmFile("Vector.gdbm", GdbmFile.READER);
                   dbVector.setKeyPacking(new StringPacking());
                   dbVector.setValuePacking(new StringPacking());
                   int doc_num = dbVector.size();
                   String doc_id = "";
                   String temp = "";
                   for (int i = 1; i <= doc_num; i++){
                        Vector doc_vector = new Vector();
                        boolean found = true;
                        doc_id = String.valueOf(i);
                        temp = (String) dbVector.fetch(doc_id);
                        StringTokenizer st = new StringTokenizer(temp);
                        while (st.hasMoreTokens()){
                             temp = st.nextToken();
                             StringTokenizer st1 = new StringTokenizer(temp, ",");
                             String term = st1.nextToken();
                             doc_vector.add(term);
                        for (int j = 0; j < query_vector.size(); j++){
                             temp = (String) query_vector.get(j);
                             if (doc_vector.contains(temp))
                                  found = found & true;
                             else
                                  found = false;
                        if (found)
                             doc_retrieved.add(doc_id);
              catch(GdbmException e){
                   System.out.println(e.getMessage());
              return doc_retrieved;
         private String Stemming(String str){
              Porter st = new Porter ();
              str = st.stripAffixes(str);
              return str;          
         private boolean search(String str){
              //stop word list
              String [] stoplist ={"a","about","above","according","across","actually","adj","after","afterwards","again",
                                       "against","all","almost","alone","along","already","also","although","always","am","among",
                                       "amongst","an","and","another","any","anyhow","anyone","anything","anywhere","are",
                                       "aren't","around","as","at","away","be","became","because","become","becomes","becoming",
                                       "been","before","beforehand","begin","beginning","behind","being","below","beside",
                                       "besides","between","beyond","billion","both","but","by","can","cannot","can't",
                                       "caption","co","co.","could","couldn't","did","didn't","do","does","doesn't","don't",
                                       "down","during","each","eg","eight","eighty","either","else","elsewhere","end","ending",
                                       "enough","etc","even","ever","every","everyone","everything","everywhere","except",
                                       "few","fifty","first","five","for","former","formerly","forty","found","four","from",
                                       "further","had","has","hasn't","have","haven't","he","he'd","he'll","hence","her","here",
                                       "hereafter","hereby","herein","here's","hereupon","hers","he's","him","himself","his",
                                       "how","however","hundred","i'd","ie","if","i'll","i'm","in","inc.","indeed","instead",
                                       "into","is","isn't","it","its","it's","itself","i've","last","later","latter","latterly",
                                       "least","less","let","let's","like","likely","ltd","made","make","makes","many","maybe",
                                       "me","meantime","meanwhile","might","million","miss","more","moreover","most","mostly",
                                       "mr","mrs","much","must","my","myself","namely","neither","never","nevertheless","next",
                                       "nine","ninety","no","nobody","none","nonetheless","noone","nor","not","nothing","now",
                                       "nowhere","of","off","often","on","once","one","one's","only","onto","or","other","others",
                                       "otherwise","our","ours","ourselves","out","over","overall","own","per","perhaps","pm",
                                       "rather","recent","recently","same","seem","seemed","seeming","seems","seven","seventy",
                                       "several","she","she'd","she'll","she's","should","shouldn't","since","six","sixty",
                                       "so","some","somehow","someone","sometime","sometimes","somewhere","still","stop",
                                       "such","taking","ten","than","that","that'll","that's","that've","the","their","them",
                                       "themselves","then","thence","there","thereafter","thereby","there'd","therefore",
                                       "therein","there'll","there're","there's","thereupon","there've","these","they","they'd",
                                       "they'll","they're","they've","thirty","this","those","though","thousand","three","through",
                                       "throughout","thru","thus","to","together","too","toward","towards","trillion","twenty",
                                       "two","under","unless","unlike","unlikely","until","up","upon","us","used","using",
                                       "very","via","was","wasn't","we","we'd","well","we'll","were","we're","weren't","we've",
                                       "what","whatever","what'll","what's","what've","when","whence","whenever","where",
                                       "whereafter","whereas","whereby","wherein","where's","whereupon","wherever","whether",
                                       "which","while","whither","who","who'd","whoever","whole","who'll","whom","whomever",
                                       "who's","whose","why","will","with","within","without","won't","would","wouldn't",
                                       "yes","yet","you","you'd","you'll","your","you're","yours","yourself","you've"};
              int i = 0;
              int j = stoplist.length;
              int mid = 0;
              boolean found = false;
              while (i < j && !found){
                   mid = (i + j)/2;
                   if (str.compareTo(stoplist[mid]) == 0)
                        found = true;
                   else
                        if (str.compareTo(stoplist[mid]) < 0)
                             j = mid;
                        else
                             i = mid + 1;
              return found;
         }

    please show us the full error message.
    it sounds like a classpath problem...

  • Previous unanswered Hot deploy of non EJB, non JSP classes

              Subject to my last post I've since seen my questions has appeared twice on this
              newsgroup, March 2001, and Nov 2000 and no responses to it those times. Aren't
              there BEA engineers reading this newsgroup who would know the answer to that question?
              http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jsp&item=3776&utag=
              http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jsp&item=5171&utag=
              

              Firstly I already did call BEA support before coming here, this is my last resort.
              I can't get a definitive answer from support. They were the ones that actually
              suggested to me that I post here in the first place. I did search the BEA edocs
              and couldn't find anything on it.
              Secondly, I am using WL 6.1 SP1, and in the thread just beneath this one, which
              I referred to directly in my opening post on this thread, I do mention this in
              the opening paragraph, in fact I give considerable detail.
              Thirdly, I never implied there was an onus on any BEA engineer to answer anything
              here. What I did mean was that given that they do read these posts and they do
              answer posts, I was merely a bit concerned that as I'm third person to ask, it
              would be strange to still get no response given that they answer other questions.
              I mean if they don't know, then who does? It's a real simple yes/no answer, it
              would take 5 seconds.
              Paul
              Robert Patrick <[email protected]> wrote:
              >
              >
              >The answer is simple -- move to WLS 6.x and use enterprise applications
              >(or web applications or an EJB jar file)
              >to package everything up into a single deployment unit and hot deploy
              >the whole deployment unit. WLS 5.1 and
              >earlier do not support hot deployment of non-servlet/non-JSP/non-EJB
              >classes.
              >
              >Mike Reiche wrote:
              >
              >> You can always call BEA Support - 1.888.232.7878 to get the help you
              >need. This
              >> newsgroup is not official BEA Support. It is out of the goodness of
              >their hearts
              >> that BEA engineers help people out here.
              >>
              >> I don't really think you wanted everyone that read your email and didn't
              >know
              >> if such a feature was available, to send you an email saying 'No, I
              >don't know
              >> if such a feature is available'. That's why there were zero responses.
              >>
              >> None of the posts you listed mention what version of WL. That makes
              >a difference.
              >> Also read the online documentation at edocs.bea.com, search for 'hot
              >deploy'.
              >>
              >> Mike Reiche
              >>
              >> "Paul H" <[email protected]> wrote:
              >> >
              >> >Subject to my last post I've since seen my questions has appeared
              >twice
              >> >on this
              >> >newsgroup, March 2001, and Nov 2000 and no responses to it those times.
              >> >Aren't
              >> >there BEA engineers reading this newsgroup who would know the answer
              >> >to that question?
              >> >
              >> >http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jsp&item=3776&utag=
              >> >
              >> >http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jsp&item=5171&utag=
              >
              >
              ><!doctype html public "-//w3c//dtd html 4.0 transitional//en">
              ><html>
              >The answer is simple -- move to WLS 6.x and use enterprise applications
              >(or web applications or an EJB jar file) to package everything up into
              >a single deployment unit and hot deploy the whole deployment unit. 
              >WLS 5.1 and earlier do not support hot deployment of non-servlet/non-JSP/non-EJB
              >classes.
              ><p>Mike Reiche wrote:
              ><blockquote TYPE=CITE>You can always call BEA Support - 1.888.232.7878
              >to get the help you need.  This
              ><br>newsgroup is not official BEA Support. It is out of the goodness
              >of
              >their hearts
              ><br>that BEA engineers help people out here.
              ><p>I don't really think you wanted everyone that read your email and
              >didn't
              >know
              ><br>if such a feature was available, to send you an email saying 'No,
              >I
              >don't know
              ><br>if such a feature is available'. That's why there were zero responses.
              ><p>None of the posts you listed mention what version of WL. That makes
              >a difference.
              ><br> Also read the online documentation at edocs.bea.com, search
              >for
              >'hot deploy'.
              ><p>Mike Reiche
              ><p>"Paul H" <[email protected]> wrote:
              ><br>>
              ><br>>Subject to my last post I've since seen my questions has appeared
              >twice
              ><br>>on this
              ><br>>newsgroup, March 2001, and Nov 2000 and no responses to it those
              >times.
              ><br>>Aren't
              ><br>>there BEA engineers reading this newsgroup who would know the answer
              ><br>>to that question?
              ><br>>
              ><br>>http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jsp&item=3776&utag=
              ><br>>
              ><br>>http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.developer.interest.jsp&item=5171&utag=</blockquote>
              ></html>
              >
              >
              

  • Display from non-MIDlet class?

    Display from non-MIDlet class?
    I havel a method in my main MIDlet that flashes up a message as an Alert:
    public void doAlert(String sAlertText) {
           Alert alSending;
           alSending = new Alert(null, sAlertText, null, AlertType.INFO);
           alSending.setTimeout(3000);
            m_display.setCurrent(alSending);
        }m_display is declared and instantiated in the main MIDlet:
    public class Boss extends MIDlet implements CommandListener {
            public static Display m_display;
            public Boss() {       /** Constructor*/
                    m_display = Display.getDisplay( this );
    }Now when I try to call this from another class:
         new Boss().doAlert("Eat lead, Bambi!");I get: "SecurityException: Application not authorized to access the restricted API". The same happens if I try to use a reference to a MIDlet, rather than to a Display. Apparently, you can't instantiate a MIDlet from with another MIDlet / class.
    So, how do you obtain a reference to the currently-running MIDlet or its Display from a different class?

    Thanks for your reply, but i finally solved it. I found a way of getting a reference to my MIDlet, so i had the control of its display.
    Maybe it could be a good idea having some classes to write to the cellular's screen without being a MIDlet, like System.out.* classes in traditional Java.
    See you.
    David.

  • Problems with String[] Class Object

    Hi guys,
    I'm writing a web server who should invoke a method of a class when asked by a client.
    My problem is that if the method that should be invoked has a String[] parameter the web server is unable to invoke it and throws a java.lang.IllegalArgumentException: argument type mismatch.
    Useful pieces of code to understand are the following:
    //create the Class[] to pass as parameter to the getMethod method
    Class[] paramType = {String[].class};
    //find the class "className" and create a new instance
    Class c = Class.forName(className);
    Object obj = c.newInstance();
    //the getMethod should find in the class c the method called nameMeth
    // having paramType (i.e. String[]) as parameter type...
    Method theMethod = c.getMethod(nameMeth, paramType);
    //here's the problematic call!!
    theMethod.invoke(obj, params);I've noted that System.out.println(theMethod); prints the signature of the method with the parameter type java.lang.String[].
    System.out.println(paramType[0]); instead prints [Ljava.lang.String;
    I know that [L means that it is an array, so why do you think that I'm having an argument type mismatch?
    Thank you                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I had no problems making that work.import java.lang.reflect.Method;
    public final class StringArray {
        public static final String CLASSNAME = "StringArray";
        public static final String METHODNAME = "myMethod";
        public static final String[] sa = { "a", "b"};
        // automatic no-args constructor
        public final void myMethod(String[] sa) {
            for(int i=0;i<sa.length;++i) {
                System.out.println(sa);
    public static final void main(String[] arg) throws Exception {
    //create the Class[] to pass as parameter to the getMethod method
    Object[] params = { sa };
    Class[] paramType = {sa.getClass()};
    //find the class "className" and create a new instance
    Class c = Class.forName(CLASSNAME);
    Object obj = c.newInstance();
    //the getMethod should find in the class c the method called nameMeth
    // having paramType (i.e. String[]) as parameter type...
    Method theMethod = c.getMethod(METHODNAME, paramType);
    //here's the problematic call!!
    theMethod.invoke(obj, params);

  • Memory leak in string class

    We have developed our application in Solaris 10 environment. While running Purify on that it shows leak in the string class. This leak is incremental and so process size keeps in increasing. If we replace string with char array, the leaks disappears and process size also becomes stable.
    Following is the snapshot of the memory leak stack reported by Purify:
    MLK: 4505 bytes leaked in 85 blocks
    * This memory was allocated from:
    malloc [rtlib.o]
    operator new(unsigned) [libCrun.so.1]
    void*operator new(unsigned) [rtlib.o]
    __rwstd::__string_ref<char,std::char_traits<char>,std::allocator<char> >*std::basic_string<char,std::char_traits<char>,std::allocator<char> >::__getRep(unsigned,unsigned) [libCstd.so.1]
    char*std::basic_string<char,std::char_traits<char>,std::allocator<char> >::replace(unsigned,unsigned,const char*,unsigned,unsigned,unsigned) [libCstd.so.1]
    std::basic_string<char,std::char_traits<char>,std::allocator<char> >&std::basic_string<char,std::char_traits<char>,std::allocator<char> >::operator=(const char*) [libCstd.so.1]
    Has anyone faced this problem earlier or is there any patch available for this?

    Over time, we have found and fixed memory leaks in the C++ runtime libraries.
    Get the latest patches for the compiler you are using. (You didn't say which one.) You can find all patches here:
    [http://developers.sun.com/sunstudio/downloads/patches/index.jsp]
    Also get the latest Solaris patch for the C++ runtime libraries, listed on the same web page.
    If that doesn't fix the problem, please file a bug report at
    [http://bugs.sun.com]
    with a test case that can be compiled and run to demonstrate the problem.

  • How to get instance of Class with its type parameters

    Hi,
    Have any of you folks been dealing with generics long enough to show me how this should be written? Or point me to the answer (I have searched as well as I could).
    I boiled down my situation to the included sample code, which is long only because of the inserted comments. And while boiling I accidentally came across a surprise solution (a bug?), but would obviously prefer a smoother solution.
    My Questions (referred to in the code comments):
    #1. Is there a way to get my parameterized type (classarg) without resorting to using the bogus (proto) object?
    #2. Can anyone understand why the "C" and "D" attempts are different? (All I did was use an intermediate variable????) Is this a bug?
    Thanks so much for any input.
    /Mel
    class GenericWeird
       /* a generic class -- just an example */
       static class CompoundObject<T1,T2>
          CompoundObject(T1 primaryObject, T2 secondaryObject)
       /* another generic class -- its main point is that its constr requires its type class */
       static class TypedThing<ValueType>
          TypedThing(Class<ValueType> valuetypeclass)
       // here I just try to create a couple of TypedThings
       public static void main(String[] args)
          // take it for granted that I need to instantiate these two objects:
          TypedThing<String>                        stringTypedThing = null;
          TypedThing<CompoundObject<String,String>> stringstringTypedThing = null;
          // To instantiate stringTypedThing is easy...
          stringTypedThing = new TypedThing<String>(String.class);
          // ...but to instantiate stringstringTypedThing is more difficult to call the constructor
          Class<CompoundObject<String,String>> classarg = null;
          // classarg has got to be declared to this type
          //    otherwise there will rightfully be compiler error about the constructor call below
          // This method body illustrates my questions
          classarg = exploringHowToGetTheArg();
          // the constructor call
          stringstringTypedThing = new TypedThing<CompoundObject<String,String>>(classarg);
       } // end main method
       // try compiling this method with only one of A,B,C,D sections uncommented at a time
       private static Class<CompoundObject<String,String>> exploringHowToGetTheArg()
          Class<CompoundObject<String,String>> classarg = null;
          /* Exhibit A: */
      ////     classarg = CompoundObject.class;
             results in compiler error "incompatible types"
             found   : java.lang.Class<GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = CompoundObject.class;
                                            ^
             I understand this.  But how to get the type information?
          /* It's obnoxious, but it looks like I will have to construct a temporary
              prototype instance of type
                 CompoundObject<String,String>
              in order to get an instance of
                 Class<CompoundObject<String,String>>
              (see my Question #1) */
          CompoundObject<String,String> proto = new CompoundObject<String,String>("foo", "fum");
          /* Exhibit B: */
      ////     classarg = proto.getClass();
             results in compiler error: "incompatible types"
             found   : java.lang.Class<capture of ? extends GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = proto.getClass();
                                            ^
          /* Exhibit C: */
      ////     classarg = proto.getClass().asSubclass(proto.getClass());
             results in compiler error: "incompatible types"
             found   : java.lang.Class<capture of ? extends capture of ? extends GenericWeird.CompoundObject>
             required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
                   classarg = proto.getClass().asSubclass(proto.getClass());
                                                         ^
          /* Exhibit D: (notice the similarity to C!): */
      ////     Class tmp1 = proto.getClass();
      ////     classarg = tmp1.asSubclass(tmp1);
          /* It compiles (see my Question #2) */
          return classarg;
       } // end method exploringHowToGetTheArg()
    } // end class GenericWeird

    Thanks so much, Bruce. (Oh my goodness, how would I have ever come up with that on my own?)
    So in summary
    This doesn't compile:
          classarg = (Class<CompoundObject<String,String>>)CompoundObject.class;but these do compile:
          classarg = (Class<CompoundObject<String,String>>)(Class)CompoundObject.class;or
          Class coclass = (Class)CompoundObject.class;
          classarg = (Class<CompoundObject<String,String>>)coclass;And this doesn't compile:
           classarg = proto.getClass().asSubclass(proto.getClass());but this does:
           Class tmp1 = proto.getClass();
           classarg = tmp1.asSubclass(tmp1);

  • List types

    Hi ,
    i'm having a little problem with list types (As the title may suggest :)) ,
    ihave class X which implements Interface Y , now i have a function that recieves a list of type X List<X> listX and another fucntion that recieves a List<Y> , i can't seem to pass the List<X> to the function which expectes a list of type Y
    ?? that's quite bizzare i think , unless i do something like that
    List<Y> yyy ;
    for (Y y : List<X>)
    yyy.add(y)
    and then i can pass yyy to the function , what's the logic in that ? i'm loosing the whole reason i use intefaces , any ideas how to solve this in a cleaner way ?

    I think that this is a limitation of Java generics. For backwards compatability, java generics aren't covariant. So if
    List<Integer> x = new ArrayList<Integer();x cannot be used in place of List<Number>. For more details, please see this reference:
    http://www.ibm.com/developerworks/java/library/j-jtp01255.html
    I don't know of any easy work-around.

  • How to add new row in KL02 trx - Activity type control data

    Hi guys.
    I am not a FI-CO consultant, but I want to add a row since KL02 transaction within a cost center, with a new fiscal year. When you access KL02 (change activity type), you set the activity type, then press Master Data and the basic screen appears. If you press the Display planning control button, you will see the "Display Activity Type Control Data" List. I wanna add a row for a specific cost center here, because the cost center I refer has not 2011 as fiscal year. I tried to use, since basic screen of KL02, use the Change planning control button, but when I set my cost center and 2011 as fiscal year, the Save button is inactive. Furthermore, I tried to press the Period screen and a message appeared "No data has been entered yet". So I dont know how to add one row for a cost center in the Planning control (Activity type control data) list of the KL02 transaction, specifically for an activity type. Do you know? Thanks in advance

    Hi,
    The list of cost centers in which the activity type is planned is given in KL02 under planning data.  In order to add a new cost center to this, you need to enter the activity type in transaction KP26 for a particular year. 
    Goto transaction KP26
    Give version - 0
    from period 1 to 12
    year - 2011
    cost center - mention the cost center
    Activity type - mention activity type
    goto overview screen F5 and add the plan price for the activity in the cost center.  This step will automatically add new row in the activity type control data.
    Hope this helps.
    Thanks,
    Ram

Maybe you are looking for

  • How to do this in SAP SD

    Companies 1. TATA 2. Godrej A customer went to godrej web site or called and ordered a refrigirator. wat godrej do here is send that order to TATA . TATA going to deliver the order to customer. and also TATA going to invoice the customer on behalf of

  • Context sensitive help, adding mapping ID

    I am updating a HTML help project file and having trouble adding additional mapping ID's. The .chm file works fine within the application we are using using the original data. However when I add to the .h file to add additional mapping ID's, its not

  • Mac Book Pro 15" Mountain Lion 10.8 Intermittent WiFi

    Hello All I know this is a well-discussed problem already but I'll try to provide relevant details to make this post not just another rant and run-around of solutions we already know. Before ML Reinstall (not erase and install): - Intermittently Safa

  • My creative cloud desktop app

    will not upgrade or open- need help reinstalling- i am a paid subscriber and can't find link to reinstall

  • Social 1.5(215) bugs

    Hi all, I upgraded my N8 Belle with Social update. Since then, I've noticed some bug on my agenda / messages incoming. Name of contact is not shown on the chatting view just phone number (but name is shown on folders view...¿?). In addition, some fac