我正在尝试ScanLocate
从活动中获取活动中的数组列表UpdateLocation
。
我正在使用startActivityForResult
方法来调用scan
填充 ArrayList 的方法wifiList
,然后我想将 ArrayList 发送到Update Location
类。
我首先startActivityForResult
打电话Update Location
:
private void getScan(){
//Create an intent to start ScanLocate
final Intent i = new Intent(this, ScanLocate.class);
//Start scanLocate with request code
startActivityForResult(i, REQUEST_READINGS);
}
接下来,在ScanLocate
我创建的sendData
方法中(注意:检查确认 ArrayList 数据在那时是完整的):
private void sendData(){
//create a new intent as container for the result
final Intent readings = new Intent(this, UpdateLocation.class);
//check that data is in wifiList
for(String s:wifiList){
Log.v(TAG,"List Items: " + s);
}
//create bundle for string array
Bundle b = new Bundle();
b.putStringArrayList(key, wifiList);
//add readings to send to updateLoc
readings.putExtras(b);
//set code to indicate success and attach Intent
setResult(RESULT_OK, readings);
//call finish to return
finish();
}
最后一部分又回到UpdateLocation
了onActivityResult
:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent readings){
super.onActivityResult(requestCode, resultCode, readings);
//check if request code matches the one set above
if(requestCode == REQUEST_READINGS){
//check if sendData() in ScanLocate was successful
if(resultCode == RESULT_OK){
//get the readings from the Intent
Log.v(TAG, "HERE");
result = getIntent().getExtras().getStringArrayList(ScanLocate.key);
Log.v(TAG, "HERE2");
for(String s : result) {
Log.v(TAG, "Location 5: " + s);
}
}else{
//ScanLocate was unsuccessful
}
}
}
第一个"Here"
显示,但是它然后落在下一行,getStringArrayList()
抛出一个空指针异常。
我已经查看了文档和之前的问题,但我看不出出了什么问题。
任何建议将不胜感激,谢谢。
以前的问题: