Asynchtask替换后可运行错误



我得到一个错误在最后一行替换我的asynctask与一个可运行的上传数据到服务器:任何指针将不胜感激。

不能从结果类型为void的方法返回值

在这一行

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);

问题是run()没有返回值,而您之前的AsyncTask解决方案允许返回值。

我期望返回一些东西。

imageProcessClass.ImageHttpRequest(ServerUploadPath, HashMapParams);

但是这里有void作为返回值

@Override
public void run() {
... 
}

我认为你需要一个新的解决方案来返回结果,也许使用一个监听器并触发回调?

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 :)

相关内容

  • 没有找到相关文章

最新更新