我正在尝试将数据从createCheckboxList
方法传递到getLRL类,但是当我尝试在post_selected
GetLRL类中调用getIntent时,我收到此错误The method getIntent() is undefined for the type GetLRL
我该如何解决?
MainActivity中的createCheckboxList:private void createCheckboxList(final ArrayList<Integer> items) {
this.items = items;
final ArrayList<Integer> selected = new ArrayList<Integer>();
...
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, GetLRL.class);
intent.putIntegerArrayListExtra("selected_route", selected);
startActivity(intent);
}
}
GetLRL中的post_selected方法:
public void post_selected() {
// here is the error
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("selected_route")) {
ArrayList<Integer> routeList = extras
.getIntegerArrayList("selected_route");
}
//new MyAsyncTask(context).execute(jSONString);
}
答案 0 :(得分:1)
GetLRL类必须是一个Activity( // Function to write a file in a non-existing directory
function writeFile(path, contents, cb){
mkdirp(getDirName(path), function(err){
if (err) return cb(err);
fs.writeFile(path, contents, cb);
});
}
// Check if log file exists, if it does not, then create it
fs.exists(__dirname + '/log/access.log', function(exists){
if(exists){
app.use(logger('common', {
stream: fs.createWriteStream(__dirname + '/log/access.log', {flags: 'a'})
}));
console.log('access.log exists!');
} else {
writeFile(__dirname + '/log/access.log', {flag: 'wx'}, function(err){
if (err) throw err;
console.log('access.log created!');
});
}
});
),如果不是,那么将抛出未定义的方法异常