【发布时间】:2017-08-10 13:23:18
【问题描述】:
我正在尝试用整数填充一个 int 数组。但是,当我打印出数组时,我只会得到相同的最后一个值,重复 25 次,这不是我想要的。我想用从蓝牙服务获得的不同整数填充数组...
weightFromDevice = intent.getExtras().getInt(BluetoothService.MESSAGE_WEIGHT_DATA); //take int values from bluetooth service
int [] _weightCount = new int[25]; // Array has a length of 25
Arrays.fill(_weightCount, weightFromDevice); //Trying to fill array with the different ints
String res = Arrays.toString(_weightCount); //Array to string for printing
displayData(res); // calling method to print array
我做错了什么?
【问题讨论】:
-
你只有一个
int为什么你认为你有25个不同的int? -
您是否尝试过调试和检查程序的状态?
-
打印 weightFromDevice。这个变量的声明到底在哪里?
-
@MuratK.蓝牙服务在另一个类中广播 25 个整数。我使用整数来计算平均值,所以我知道它有效。我似乎无法让我的阵列工作......
-
这就是填充的作用:用相同的值填充数组