方法声明无效,异步任务上下文中需要返回类型

时间:2016-10-19 06:15:16

标签: android android-asynctask

我试图在异步任务中定义一个上下文,但它会让我回到错误之下。不确定陈述

有什么问题
In file included from /usr/include/c++/5/thread:39:0,
                 from assgn4.cpp:17:
/usr/include/c++/5/functional: In instantiation of ‘struct std::_Bind_simple<void (*(std::reference_wrapper<TTAS()>))(TTAS)>’:
/usr/include/c++/5/thread:137:59:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(TTAS); _Args = {std::reference_wrapper<TTAS()>}]’
assgn4.cpp:186:60:   required from here
/usr/include/c++/5/functional:1505:61: error: no type named ‘type’ in ‘class std::result_of<void (*(std::reference_wrapper<TTAS()>))(TTAS)>’
       typedef typename result_of<_Callable(_Args...)>::type result_type;
                                                             ^
/usr/include/c++/5/functional:1526:9: error: no type named ‘type’ in ‘class std::result_of<void (*(std::reference_wrapper<TTAS()>))(TTAS)>’
         _M_invoke(_Index_tuple<_Indices...>)
         ^

这里说“无效的方法声明,需要返回类型”

有人可以帮忙!

1 个答案:

答案 0 :(得分:0)

你可以将它作为param传递给错误的,你应该以另一种方式使用异步任务。

将UI相关代码放在onPostExecute方法中。在那里你也可以访问上下文。

检查此示例on stackoverflow