配列アイテムを並べ替えて古いインデックスを新しい配列に格納する必要があるので、そのためのコレクションを試してみtreemap
ました。期待どおりにコレクションで完全な出力が得られましたが、コレクションを配列に変換すると問題が発生します。
float[] array = new float[10];
array[0] = 11;
array[1] = 10;
array[2] = 3;
array[3] = 40;
array[4] = 5;
array[5] = 60;
array[6] = 4;
array[7] = 41;
array[8] = 110;
array[9] = 8;
Map<Float, Integer> map = new TreeMap<Float, Integer>();
for (int i = 0; i < array.length; ++i) {
map.put(array[i], i);
}
Collection<Integer> indices = map.values();
System.out.println("indices"+indices);
String s[] = (String[])indices.toArray(new String[0]);
for (int i = 0, n = s.length; i < n; i++)
{
System.out.println(s[i]);
}
次のようなエラーが発生します。
04-18 14:55:13.380: ERROR/AndroidRuntime(859): FATAL EXCEPTION: main
04-18 14:55:13.380: ERROR/AndroidRuntime(859): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jcord/com.jcord.Jcord_for_Con_lat_long_to_east_nothenActivity}: java.lang.ArrayStoreException
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.os.Looper.loop(Looper.java:123)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at java.lang.reflect.Method.invoke(Method.java:521)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at dalvik.system.NativeStart.main(Native Method)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): Caused by: java.lang.ArrayStoreException
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at java.util.AbstractCollection.toArray(AbstractCollection.java:357)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at com.jcord.Jcord_for_Con_lat_long_to_east_nothenActivity.onCreate(Jcord_for_Con_lat_long_to_east_nothenActivity.java:50)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-18 14:55:13.380: ERROR/AndroidRuntime(859): ... 11 more