Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why does my array contain all nulls?

System.out.println(loo); -> This will show what's inside the array properly
System.out.println(tokFix[i]); -> While this will show all null's




Java

public static String[] parseFixMsg(String fixMsg1,String fixMsg2){
    int i = 0;
    int size = getArraySize(fixMsg1);
    String[] tokFix = new String[size];
    StringTokenizer st = new StringTokenizer(fixMsg2,(Character.toString((char)01))+"]");
    st.nextToken();


    while (st.hasMoreTokens()) {

        tokFix[i] = st.nextToken();
        String loo = tokFix[i];
        i++;
        <big>System.out.println(loo);
        System.out.println(tokFix[i]); </big>       }
    return tokFix;
}


public static int getArraySize(String fixMsg){
    int size = 1;
     StringTokenizer st = new StringTokenizer(fixMsg,(Character.toString((char)01))+"]");


     st.nextToken();
        while (st.hasMoreTokens()) {
            st.nextToken();
            size+=1;
        }
        return size;
}
Posted

1 solution

You incremented i before checking. Of course the next item is empty, you haven't populated it yet.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900