1

This is probably a question with a blindingly obvious answer. I just can't see it, and will probably feel very small when someone points it out to me clearly.

I'm using Android at the Eclair MR1 level, so my Android Manifest has:

<uses-sdk android:minSdkVersion="7" />

In my MainActivity, I have a byte[] that I want to realloc to a larger size.

Java SE 6 has the java.util.Arrays class with static methods to do that for every elementary type. I can see that class documented in the android docs at http://developer.android.com/reference/java/util/Arrays.html#copyOf%28byte[],%20int%29

Here's my code:

    byte [] padToLength (byte[] plain) {

    try{
        byte[] plainpad2 = java.util.Arrays.copyOf(plain, plain.length+10);  //why won't this compile?
    } catch (Exception e) {

    }

But when I use that, I get a compilation error in Eclipse, saying "the method copyOf(byte[], int) is undefined for the type Arrays.

Can anyone suggest what I am doing wrong?

2

1 Answer 1

1

Arrays.copyOf(byte[], int) is not defined for API Level 7. At that link you provided, have a look in the top-right corner and you'll see a checkbox that says "Filter By API Level". Selecting 7 removes that method.

Why are you working with arrays anyway? In Java you should almost always use ArrayList unless you are experiencing performance problems. In that case, you don't have to worry about the size of your array at all. If your function must accept a byte[] parameter, then I'd suggest invoking something like List<Byte> myList = Arrays.asList(plain).

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

1 Comment

You and MH nailed it, and I feel suitably small. This API came in with API level 9. Thank you! As you guessed, performance is the top priority, which is why I am working with arrays of atomic types.

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.