0

I can't seems to find out what what is wrong with my codes? i can't pass in non-empty String value into an empty String array?

String[] profiles = wifiPositioningServices.GetAllProfileData();

ArrayList<String[]> macAddresses = new ArrayList<String[]>();
String[] macAddressTemp=null;

    //store all profile data into a ArrayList of Profile objects
    for(int i=0; i<profiles.length; i++){
        String[] result = profiles[i].split(",");
        Profile profile = new Profile();
        profile.setProfileName(result[0]);
        profile.setOwner(result[1]);
        profile.setMap(result[2]);
        profile.setVisible(result[3]);
        boolean visible = Boolean.valueOf(result[3]);
        if(visible){
            //if visible is true, then add profile name and mac filters into arraylist 
            profileNames.add(result[0]);
            int cnt=0;
            for(int j=4; j<result.length; j++){
                profile.setMacFiltersList(result[j]);
                Log.e("Text:", result[j]);
                macAddressTemp[cnt] = result[j];
                ++cnt;
            }
            macAddresses.add(macAddressTemp);
        }
        profileList.add(profile);
    }

Java show a nullpointer exception at the line "macAddressTemp[cnt] = result[j];". I am sure that result[j] is not empty cause i was able to print it out via the log msg.

1
  • You're code is wrong. Check my answer bellow. Go Pumas! Commented Sep 17, 2011 at 3:35

4 Answers 4

3

Use an ArrayList instead.

ArrayList<String> macAddressTemp = new ArrayList<String>(100); //check capacity
macAddressTemp.add(result[j]);

EDIT:

You changed your code wrong. This ArrayList<String[]> macAddresses = new ArrayList<String[]>(); is creating a List that contains arrays. You have to create a List that contains String. Check the code above.

Sign up to request clarification or add additional context in comments.

1 Comment

i guess i just have to revert back to my previous method which is to store the list of mac addresses i retrieved in the arrayList in the Profile object.
1

The array macAddressTemp is null.

Comments

0

The NPE is thrown because macAddressTemp is null. You probably want to declare and initialize macAddressTemp inside of the outer loop.

Comments

0

You explicitly set it to null:

String[] macAddressTemp=null;

You need to allocate some space for the array, or use a collection.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.