Converting ArrayList to List ives NullPointerException

Hello,
I have block of code.
    private ArrayList<SomeBean> list;
    private List<SomeBean> listNew;
    getter and setters
            for ( SomeBean itr : list ) {
               listNew.add(itr);
Gives me NullPointerException

You are not obliged to initialize it as List, it's just that you can't initialize with an abstract class. You have to use a class which is extended from the abstract class. Only such a class adds the needed information about the implementation, which the abstract class misses deliberately.
private List<SomeBean> listNew = new ArrayList<SomeBean>();
Now hte compiler knows which implementation of List you like to use.
If you return the list you return it as List<SomeBean>.
Timo

Similar Messages

  • Converting enumerations to lists with generics

    hello...
    i want to list off system properties and sort them.
    how can you convert enumerations to lists with generics?
    i tried the following in eclipse, but it fails...
         Properties properties = System.getProperties( ) ;
         Enumeration<?> enumeration = properties.propertyNames( ) ;
         ArrayList<String> arrayListEnum = Collections.list( enumeration ) ;
         Collections.sort( arrayListEnum ) ;

    Because the type parameter of Enumeration (<?>) is not compatible with the type parameter of ArrayList (<String>).
    You'll have to do some manual casting yourself.
    Unfortunately, there's nothing to guarantee that system property keys or values are strings (hence why Enumeration<?> and no Enumeration<String>) so you'll need to cope if you find one that isn't.

  • How to convert arraylist into array

    how to convert arraylist into array?

    If you are using generics, I would use this version of toArray:
    List < X > list = ...
    X[] array = list.toArray(new X[list.size()]);If you are not using generics, that same thing looks like:
    List  list = ...
    X[] array = (X[]) list.toArray(new X[list.size()]);

  • Converting Arrays to List

    Hi,
    I have the following function that converts String[] to List of int and it's working
    private String putSelect(){
            String msg = SUCCESS;
            try{
                if (session.get("selectCat") != null){               
                    String[] aux = (String[])session.get("selectCat");
                    List aux2 = new ArrayList();
                    for (int i=0;i<aux.length;i++){
                      aux2.add(Integer.parseInt(""+aux));
    setSelectCat(aux2);
    }catch (Exception e) {       
    msg = ERROR;
    System.out.println(e.getMessage());
    return msg;
    but I know that is possible to convert from array to list using :
    Array.asList
    but I need that the resulting list be of int not String, is there a way to modify this setSelectCat(Arrays.asList((String[])session.get("selectCat"))); in order for that to be possible?
    thanks, V

    if you're using java 1.5, then a better loop might be:
    for (String num : aux) {
       aux2.add(Integer.parseInt(num));
    }The variable aux is already a String, so doing "" + aux is pointless. I don't know if a compiler would clean that up for you or not. I'm told that a 'for / in' loop as coded above is marginally faster than an incrementor loop.
    Enjoy!

  • How to convert the alv list data into pdf format

    Hi Expersts,
                      Is it possible to convert the alv list output data into PDF format? if yes, then please help me with this issue.
    thanks in advance,
    Regards,
    Samad

    hii samad,
    you can go through these link.i hope it ll solve your purpose
    How to convert list output to PDF
    Display ALV list output in PDF format
    regards,
    Shweta

  • Convert ArrayList into XML file

    Hi,
    Can anyone tell me how to convert ArrayList to XML file and save that file.
    Manoj

    There is an easy to understand example here:
    http://totheriver.com/learn/xml/code/XMLCreatorExample.java.
    You only have to replace Book objects from example with objects you need.

  • Add file types to convert to pdf list

    Using Acrobat pro 8.1.2 on Windows XP sp2. When I try to convert to pdf from doc or xls file I get an error message saying "not a supported file type". I checked the prefernces and noted that Microsoft Office is not included in the convert to pdf list. So how do I add Microsoft Office to the list?

    First which version of MS Office are you using?
    In MS Office does the PDF Maker work?
    Have you enabled PDF Maker in MS Office?
    MS Office does not automatically allow PDF Maker macros to work by default. One has to enabale the PDF Maker macros.
    The PDF Maker macros may not recognize the new MS Office file types, so you will have to save your files to the Office 2003/XP types.

  • Why does  ArrayList implement List when extending AbstractList

    Hi
    I am unable to understand why would the ArrayList class implement the List interface, when it is already extending the AbstarctList class. If anyone can explain, it would be a great help.

    Why does ArrayList implement List when extendingAbstractList
    It is a question of style. ArrayList'simplementing
    List is a crucial piece of information, whereasits
    extending AbstractList is a kind of implementation
    detail. If would not matter much to the user if it
    did not extend AbstractList but implemented List
    directly.So why don't those subclasses of ArrayList step up
    and implement List again? I agree, extending
    ArrayList is an implementation detail, and in fact
    perhaps they should have made ArrayList a field
    rather than a superclass...Because those subclasses job is not to be a List but to be an extension of ArrayList. In general if you wanted to be a List you would be extending AbstractList. You don't just implement List because you happen to have the right methods, you implement List because you feel being a List is part of that classes main behavior.
    Its a suttle point but I feel its more than a matter of style. Its a matter of correctness.
    Also, ArrayList could use composition by having an AbstractList member within itself. In this case it would implement List as well and achieve the same result. Letting users know it intends to fill the role of a List.

  • Convert Object to List

    I have a method takes a Object and I need to convert it to List. What is the best way to do that?

    The same way you convert a thing to an apple.
    Either the thing is an apple, then you can help yourself by calling it "apple" instead of "thing" (namely casting the handling reference to the type "apple" --> Apple a = (Apple) theThing; ), or it isn't an apple at all and there's nothing you can do about it.
    If you cast, please do an instanceof check first. But I'd rather suggest passing List-type arguments right away if you can.

  • How do I convert a distribution list to a mailbox

    Is there a way to convert a distribution list to a mailbox ?

    Hi, 
    While this  is possible, we have found that once you have moved the smtp address to the newly created mailbox, any user who had the smtp address cached in their outlook profile will receive a NDR, and would require to delete the auto-completed address
    before being able to send mail to it.
    Is there any specific attributes that can be copied/migrated across to prevent this disruption?
    We have an urgent requirement to change the distribution group to a user mailbox that is frequently used company wide and would be very keen to ensure the transition is seamless from an end-user perspective.
    Any help would be much appreciated,
    MKA

  • Is there a wa to convert a numbered list into sections / outline mode indented?

    Is there a wa to convert a numbered list into sections / outline mode indented?

    I think you need to describe in more detail what you want to achieve. Are you talking about Document outline? I myself haven't used that feature. I would read about it in the Pages User Guide to get familiar on how it works. Or I would read the Missing Manual for iWork which is a very good book about iWork and Pages.

  • Help needed in  converting ArrayList to ArrayCollection

    I am converting an ArrayList (Java) to ArrayCollection of Flex .
    Please help me in this , i dont know whether this is correct approach or not
    I have a Created a User VO ActionScript class  on flex with two properties as uname , pass .
    [Bindable]       
            var result:ArrayCollection
    private function displayDetails(event:ResultEvent):void
    result = event.result as ArrayCollection;
    <mx:DataGrid  dataProvider="{result}">
                    <mx:columns>
                        <mx:DataGridColumn headerText="UserName" dataField="uname"/>
                        <mx:DataGridColumn headerText="Password" dataField="pass"/>
                    </mx:columns>
                </mx:DataGrid>
    This is from my Java DAO File :
                ResultSet rs = stmt.executeQuery("select NAME , PASS from Users");
                list = new ArrayList();
                while (rs.next()) {
                    User user = new User();
                    user.setUname(rs.getString(1));
                    user.setPass(rs.getString(2));
                    list.add(user);
            return list;
    With the below code ,the displayed DataGrid is empty with no data , please help me where i am doung wrong
    Do i need to do anything more ?? The data is coming well on to the lcds server console .
    Please help .

    Hi Kiran,
    Debugging solves most of the problems that you encounter ......you need to use a lot of debuggung so that you will come to know exactly what's
    happening indeed...
    So just put a break point at your displayDetails(event:ResultEvent):void  function and try to watch the event variable and check the event.result
    What is the datatype of the event.result ...Are you getting any data or is it null..???
    Please make these observations and let me know...
    Thanks,
    Bhasker

  • Convert File[] to List File

    Hi ,
    I have the following File[]
    File[] file1 = (File[]) ((List) t.getTransferData(DataFlavor.javaFileListFlavor)).toArray();At some point, I need to convert this File[] file1 to List<File>
    How can I do it?
    Please help.
    Any help in this regard will be well appreciated with points.
    Regards,
    Rony

    RonyFederer wrote:
    List<File> ff = Arrays.asList(files);Am I correct?Remember that the Arrays.asList() method returns a list that is backed by the array. Since it is not possible to resize an array, you are not allowed to add or removed from the list. If you want a workable list you could use an ArrayList .

  • Convert SAP spoolOR list to excel and send as an email attachment

    Hello All Masterminds ,
      Iu2019ve developed a utility, in which users has to maintain one u201CZu201D view where they can give any report name, type of attachment (PDF, XLS, TXT) and sender email addresses.u201DNote: thing to remember here is Iu2019m creating XLS,TXT,PDF format dynamicallyu201D 
    It is working fine for PDF. Iu2019m submitting the program and creating spool and converting it to PDF and sending to their emails as an attachment.  It looks fantastic. When Iu2019m doing the same thing for XLS it is showing messy output, I tried many functions and search lots of unanswered, unfinished SDN posts. I almost tried every single clue given in these posts but no luck. Email part is working fine using classes (  l_document = cl_document_bcs=>create_document , l_document->add_attachment , l_send_request->set_document( l_document ).,cl_sapuser_bcs=>create( l_uname ).,l_send_request->add_recipient,  l_send_request->set_send_immediately( '' ).  ) .
    My real deal is to create a beautiful XLS out put. I also tried FMs LIST_FROM_MEMORY and LIST_TO_ASCI but no-luck. I thought instead of spool if I use u201CSubmit  EXPORTING LIST TO MEMORY u201C option may be It works but BIG NO 
       Iu2019m sure some genius out there has done something like his , I ain`t genius that is why I am stuck   Please guys throw me some bones .  As I said, I am able to do most of the things. I need some magic code /answer which turns my messy, ugly unformatted excel sheet attachment to beautiful u201Cpiece of art u201CExcel output.
      Here are the FMs I tried so far with different combinations.
    CALL FUNCTION 'LIST_FROM_MEMORY'
    CALL FUNCTION 'LIST_TO_ASCI'
    CALL FUNCTION 'GUI_DOWNLOAD'
    CALL FUNCTION 'RSPO_DOWNLOAD_SPOOLJOB'
    CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
    CALL FUNCTION 'CONVERT_OTF'
    CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
    And logic like to get rid of things getting in Asci tables
    cl_abap_char_utilities=>newline.
    cl_abap_char_utilities=>horizontal_tab
    cl_abap_char_utilities=>VERTICAL_TAB
    cl_abap_char_utilities=>cr_lf
    FIELD-SYMBOLS: <lfs_table>,    " Internal table structure
                     <lfs_con>.      " Field Content
      DATA: l_text TYPE char1024.     " Text content for mail attachment
      DATA: l_con(50) TYPE c.        " Field Content in character format
    Columns to be tab delimeted
      LOOP AT FINAL ASSIGNING <lfs_table>.
        DO.
          ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
                 TO <lfs_con>.
          IF sy-subrc NE 0.
            CONCATENATE c_cr l_text INTO l_text.
            APPEND l_text TO i_attach.
            EXIT.
          ELSE.
            CLEAR: l_con.
            MOVE <lfs_con> TO l_con.
            CONDENSE l_con.
            IF sy-index = 1.
              CLEAR: l_text.
              MOVE l_con TO l_text.
            ELSE.
              CONCATENATE l_text l_con INTO l_text
                 SEPARATED BY c_tab.
            ENDIF.
          ENDIF.
        ENDDO.
      ENDLOOP.
    Posts : https://forums.sdn.sap.com/click.jspa?searchID=14756211&messageID=4401940
    https://forums.sdn.sap.com/click.jspa?searchID=14756211&messageID=4796657
    https://forums.sdn.sap.com/search.jspa?threadID=&q=convertspoolintoexcelformatforsendingmail&objID=c42&dateRange=all&numResults=30&rankBy=10001
    Will appreciate your help and time.
    Thanks,
    Saquib Khan

    Hi,
    i send excel-att like this.
    REPORT Z_EMAIL_CL_BCS MESSAGE-ID ZZ.
    More examples here BCS_EXAMPLE_* with se38
    DATA: SEND_REQUEST       TYPE REF TO CL_BCS.
    DATA: SUBJECT            TYPE SO_OBJ_DES.
    DATA: ATT_TYPE           TYPE SOODK-OBJTP.
    DATA: IT_TEXT            TYPE BCSY_TEXT.
    DATA: WA_TEXT            LIKE SOLI.
    DATA: IT_BIN             TYPE SOLIX_TAB.
    DATA: WA_BIN             TYPE SOLIX.
    DATA: DOCUMENT           TYPE REF TO CL_DOCUMENT_BCS.
    DATA: SENDER             TYPE REF TO CL_SAPUSER_BCS.
    DATA: RECIPIENT          TYPE REF TO IF_RECIPIENT_BCS.
    DATA: BCS_EXCEPTION      TYPE REF TO CX_BCS.
    DATA: SENT_TO_ALL        TYPE OS_BOOLEAN.
    Bytes der Datei
    DATA: IT_LENGHT          TYPE SO_OBJ_LEN.
    DATA: N10(10)            TYPE N.
    CONSTANTS: CON_NEWL TYPE ABAP_CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>NEWLINE,
               CON_TAB  TYPE ABAP_CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    CONSTANTS: CON_NEWL TYPE X VALUE '0D', "OK for non Unicode
                CON_TAB  TYPE X VALUE '09'. "OK for non Unicode
    START-OF-SELECTION.
      PERFORM MAIN.
    END-OF-SELECTION.
    FORM MAIN.
      TRY.
        -------- create persistent send request ------------------------
          SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
          PERFORM HEAD_CONT.
          PERFORM XLS_ATT.
        add document to send request
          CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).
        --------- set sender -------------------------------------------
          SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ).
          CALL METHOD SEND_REQUEST->SET_SENDER
            EXPORTING
              I_SENDER = SENDER.
        --------- set recipent -----------------------------------------
          RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
                                            'the email adress' ).
        add recipient with its respective attributes to send request
          CALL METHOD SEND_REQUEST->ADD_RECIPIENT
            EXPORTING
              I_RECIPIENT = RECIPIENT
              I_EXPRESS   = 'X'.
         RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
                                           'the email adress 2' ).
        add recipient with its respective attributes to send request
         CALL METHOD SEND_REQUEST->ADD_RECIPIENT
           EXPORTING
             I_RECIPIENT = RECIPIENT
             I_EXPRESS   = 'X'.
        ---------- send document ---------------------------------------
          CALL METHOD SEND_REQUEST->SEND(
            EXPORTING
              I_WITH_ERROR_SCREEN = 'X'
            RECEIVING
              RESULT              = SENT_TO_ALL ).
          COMMIT WORK.
        CATCH CX_BCS INTO BCS_EXCEPTION.
          WRITE: 'Fehler aufgetreten.'(001).
          WRITE: 'Fehlertyp:'(002), BCS_EXCEPTION->ERROR_TYPE.
          EXIT.
      ENDTRY.
    ENDFORM.                    "main
    FORM HEAD_CONT.
      CLEAR: IT_TEXT[], WA_TEXT, SUBJECT.
      ATT_TYPE = 'RAW'.
      CONCATENATE 'Betreffzeile am' SY-DATUM 'um' SY-UZEIT
      INTO SUBJECT SEPARATED BY SPACE.
      WA_TEXT = 'Hello!'.
      APPEND WA_TEXT TO IT_TEXT.
    WA_TEXT = 'dieses ist eine Testmail'.
    APPEND WA_TEXT TO IT_TEXT.
    WA_TEXT = 'Gruß'.
    APPEND WA_TEXT TO IT_TEXT.
      DESCRIBE TABLE IT_TEXT LINES N10.
      N10 = ( N10 - 1 ) * 255 + STRLEN( WA_TEXT ).
      IT_LENGHT = N10.
      DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                I_TYPE    = ATT_TYPE
                I_TEXT    = IT_TEXT
                I_LENGTH  = IT_LENGHT
                I_SUBJECT = SUBJECT ).
    ENDFORM.                    "HEAD_CONT
    FORM XLS_ATT.
      DATA: BEGIN OF ITAB OCCURS 0,
            MATNR     LIKE MARA-MATNR,
            MTART     LIKE MARA-MTART,
            MATKL     LIKE MARA-MATKL,
            BRGEW     LIKE MARA-BRGEW,
          END   OF ITAB.
      DATA: BRGEW(18).
      CLEAR: IT_BIN[], WA_BIN, SUBJECT.
      SELECT MATNR MTART MATKL BRGEW INTO TABLE ITAB FROM MARA UP TO 10 ROWS.
      CONCATENATE 'Material'      CON_TAB
            'Materialart'   CON_TAB
            'Warengruppe'   CON_TAB
            'Bruttogewicht' CON_NEWL
              INTO WA_BIN.
      APPEND WA_BIN TO IT_BIN.
      LOOP AT ITAB.
        WRITE ITAB-BRGEW TO BRGEW.
        CONCATENATE ITAB-MATNR CON_TAB
                    ITAB-MTART CON_TAB
                    ITAB-MATKL CON_TAB
                         BRGEW CON_NEWL
                    INTO WA_BIN.
        APPEND WA_BIN TO IT_BIN.
      ENDLOOP.
      ATT_TYPE = 'XLS'.
      SUBJECT = 'My XLS attachment'.
      DESCRIBE TABLE IT_BIN LINES N10.
      N10 = ( N10 - 1 ) * 255 + STRLEN( WA_BIN ).
      IT_LENGHT = N10.
      CALL METHOD DOCUMENT->ADD_ATTACHMENT
        EXPORTING
          I_ATTACHMENT_TYPE    = ATT_TYPE
          I_ATT_CONTENT_HEX    = IT_BIN
          I_ATTACHMENT_SIZE    = IT_LENGHT
          I_ATTACHMENT_SUBJECT = SUBJECT.
    ENDFORM.                    "XLS_ATT
    Perhaps it helps.
    regards, Dieter

  • Convert named access list to line numbers

    I printed out a document months ago which has since then disappeared into my mountains of paperwork. Somewhere in that document listed a command that converted an extended, named access list to one with line numbers. I even recall that you could input the line interval into the conversion process (so lines would be 5,10,15 etc or 10,20,30 etc).
    I just upgraded a 6509, and I'm ready to put line numbers in my access list, and can't find the command - a new Cisco search is coming up empty. Can anyone recall what the command is?? Again, it's for converting an existing access-list with no line numbers to one with line numbers.
    Thank you!

    Hi Emily,
    I guess this is what you are looking for. I have not tried it my self but would like to test it out.
    1. enable
    2. configure terminal
    3. ip access-list resequence access-list-name starting-sequence-number increment
    4. ip access-list {standard | extended} access-list-name
    5. sequence-number permit source source-wildcard
    or
    sequence-number permit protocol source source-wildcard destination destination-wildcard [precedence precedence] [tos tos] [log] [time-range time-range-name] [fragments]
    6. sequence-number deny source source-wildcard
    or
    sequence-number deny protocol source source-wildcard destination destination-wildcard [precedence precedence] [tos tos] [log] [time-range time-range-name] [fragments]
    7. Repeat Step 5 and/or Step 6 as necessary, adding statements by sequence number where you planned. Use the no sequence-number command to delete an entry.
    8. end
    9. show ip access-lists access-list-name
    This link should help :
    http://www.cisco.com/en/US/products/sw/iosswrel/ps1838/products_feature_guide09186a0080134a60.html
    regards,
    -amit singh

Maybe you are looking for

  • Why do I have to pay to get help for Itunes?

    First off, why do I have to pay to get help? That is absolutely ridiculous when it is someone's JOB to be a "support" for this. I've had a reoccuring problem of my music not playing on my IPhone. I fixed it the first time by taking off all the music

  • HT5006 Earthquake iOS built-in option not on iPhone bought outside Japan but using in Japan

    I bought my iPhone in Australia and brought it with me to Japan and now use it on the docomo network. I'd like to have the iOS built-in Earthquake warning option, but I can't find it on my phone. How do I get this option on my Australian iphone in Ja

  • Doubt in PreparedStatement

    i am using two tables(walk and run - two are linked with forein key) . In my application by using one input form , sending data into these two tables. i used the PreparedStatement with sql qurey as follows: PreparedStatement ps=con.prepareStatement("

  • Getting undefined reference error

    Hi Iam using GCC 4.1.2 in solaris with Oracle 9.0.2 I have the following program #include <iostream.h> #include <occi.h> using namespace oracle::occi; using namespace std; int main() Environment *Env = Environment::createEnvironment(Environment::DEFA

  • File Exists on Internet

    I can use Test-Path to find out if C:\Test.csv exists or not How to find out if a file exits on Internet, eg. http://www.domain.com/test.csv ?