這裏是我的代碼:我如何獲得在方法DoInBackground中聲明的變量?
class OpenERP extends AsyncTask<Context, Void, Integer>
@Override
protected Integer doInBackground(Context ... params) {
try{
final Integer id = (Integer) models.execute("execute_kw", asList(
db, uid, password,
"pointage.task", "create",
asList(new HashMap() {
{
put("name", "Hello");
}
})
));}
catch (XmlRpcException e) {
Log.e(TAG, "Xml Rpc Excception " + e.getMessage());
}
return id;
}
@Override
protected void onPostExecute(Integer id) {
hello.setText(id);
}
}
我想要得到的變量ID在我後面的代碼使用。 我得到的錯誤:無法解析symbil id! 因爲它是在集團內部聲明的{try}。 要做什麼??!
是的,我想它就像tht,但變量id是在集成塊try {}中聲明的,所以當我把返回id,我得到:無法解析可變ID! @RohitArya – Steven7
如果你可以''返回''doInBackground',那麼你可以使用它。更新完整的代碼,如果你不知道如何做到這一點。 –
我更新我的代碼@RohitArya,我該如何改變它,所以我可以使用變量ID? – Steven7