0
我正在从Android123应用程序接收RFDuino
的数据并在Line Chart
上显示它。如何将接收到的数据存储在数组中?
在我的Mainactivity
中,broadcastReceiver
在接收时将数据发送到方法addData
。
private final BroadcastReceiver rfduinoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (RFduinoService.ACTION_CONNECTED.equals(action)) {
upgradeState(STATE_CONNECTED);
} else if (RFduinoService.ACTION_DISCONNECTED.equals(action)) {
downgradeState(STATE_DISCONNECTED);
} else if (RFduinoService.ACTION_DATA_AVAILABLE.equals(action)) {
addData(intent.getByteArrayExtra(RFduinoService.EXTRA_DATA));
}
}
};
的addData方法如下:
public void addData(byte[] data) {
View view = getLayoutInflater().inflate(android.R.layout.simple_list_item_2, dataLayout, false);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
String riz = HexAsciiHelper.bytesToHex(data);
t1 = Integer.parseInt(riz, 16);
String testString = String.valueOf(t1);
text1.setText(testString);
dataLayout.addView(view,LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
}
现在,我想到t1的值存储到一个数组。问题是,当我尝试这样做时,发生NullPointerException
并且程序停止。
任何帮助,将不胜感激。
你在哪里声明't1'?另外发布整个堆栈跟踪,* npe发生*没有说多少 – wasyl
除了输入'data'数组外,我在代码中看不到数组。向我们展示您编写的代码以尝试执行此操作,以及来自例外的堆栈跟踪。 –