[英]Runnable error After Asynchtask replacement
I am getting an error on the last line below after replacing my asynctask with a runnable to upload data to server: Any pointers will be appreciated.在将我的 asynctask 替换为可运行的以将数据上传到服务器后,我在下面的最后一行出现错误:任何指针将不胜感激。
Cannot return a value from a method with void result type无法从具有 void 结果类型的方法返回值
on this line在这条线上
return *imageProcessClass.ImageHttpRequest(ServerUploadPath, HashMapParams);
ExecutorService service = Executors.newSingleThreadExecutor ( );
service.execute ( new Runnable ( ) {
@Override
public void run() {
//preexecute
runOnUiThread ( new Runnable ( ) {
@Override
public void run() {
progressDialog = ProgressDialog.show( UploadActivity.this,"Your Data is Uploading To Our Servers",
"Please Wait And Ensure Data is On With Bundles. 3G or WiFi data is preferred",false,false);
}
} );
//doinbackground
ImageProcessClass imageProcessClass = new ImageProcessClass ();
HashMap<String,String> HashMapParams = new HashMap<>();
HashMapParams.put(USER_NAME, userName);
HashMapParams.put(USER_EMAIL, userEmail);
HashMapParams.put(USER_PHONE, userPhone);
HashMapParams.put(ImagePath1, imageView1);
return imageProcessClass.ImageHttpRequest(ServerUploadPath, HashMapParams);
The problem is that run()
has no return value where your previous solution with AsyncTask
allows a return value.问题是run()
没有返回值,而您之前使用AsyncTask
的解决方案允许返回值。
I expect this return something.我希望这能带来一些回报。
imageProcessClass.ImageHttpRequest(ServerUploadPath, HashMapParams);
but this has void
as a return value但这有void
作为返回值
@Override
public void run() {
...
}
I think you need a new solution for returning the result, maybe working with a Listener and trigger the callback?我认为您需要一个新的解决方案来返回结果,也许使用监听器并触发回调?
interface ResultListener{
public void onResult(result: ResultType)
}
@Override
public void run() {
...
listener.onResult(imageProcessClass.ImageHttpRequest(ServerUploadPath, HashMapParams);)
}
// Sorry I'm not very familiar with Java anymore, hope you get the idea :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.