Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't use Arrays.copyOfRange

I don't seem to be able to access Arrays.copyOfRange in my Android project in Eclipse Indigo 3.7.1 On Ubuntu 11.10.

My JRE is java-6-openjdk which I thought included Arrays.copyOfRange

For example, if I have this code:

int[] debug = new int[5];
int[] x = Arrays.copyOfRange(debug,0,4);

Eclipse tells me

The method copyOfRange(int[], int, int) is undefined for the type Arrays

I don't understand because the Android reference Arrays includes this method for Arrays.

Any ideas?

like image 493
aez Avatar asked Jan 21 '12 14:01

aez


1 Answers

The method Arrays.copyOfRange() wasn't introduced until API level 9. Make sure you are using that as the minimum SDK.

Also, you are indexing incorrectly. In java if you have an array of size 5 the indices range from 0->4

Change your code to this:

int[] debug = new int[5];
int[] x = Arrays.copyOfRange(debug,0,4); // use 4 instead of 5
like image 197
slayton Avatar answered Oct 04 '22 16:10

slayton