java - Android AsyncTask 错误,试图分配较弱的访问权限。

标签 java android android-asynctask

我被这个问题困住了,我继续收到以下错误:

'processFinish(Boolean)' in 'Anonymous class derived from MainActivity.AsyncGETRequestProcess.AsyncResponse' clashes with 'processFinish(Boolean)' in MainActivity.AsyncGETRequestProcess.AsyncResponse'; attempting to assign weaker access privileges ('packageLocal'); was public.

我想要完成的是,在我收到来自 Intent 的数据后,从 MainActivity 内部运行 AsyncTask。

这是我收到错误的 onResume 代码,也是调用 Asynctask 的地方:

 @Override
    protected void onResume(){
        super.onResume();

        IntentFilter intentFilter = new IntentFilter("cb.MainActivity.WebServiceReceiver.ReturnedReceivedDataFilePath");
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                //Get message from WebServiceReceiver Intent
                String ReceivedDataFilePath = intent.getStringExtra("WebServiceReceiver_ReturnedReceivedDataFilePath");


                new AsyncGETRequestProcess(new AsyncGETRequestProcess.AsyncResponse(){
                      //THE ABOVE ERROR HAPPENS HERE... processFinish
                      @Override
                      void processFinish(boolean success){
                        if(success){
                            MainActivity.getInstance().txtStatus.setText("Loading screen...");
                            Intent RouteScreenActivityIntent = new Intent(MainActivity.getInstance(), RouteScreenActivity.class);
                            MainActivity.getInstance().startActivity(RouteScreenActivityIntent);
                        }else{
                            //ERROR MSG
                        }
                        //Stop the spinner in MainActivity
                        MainActivity.getInstance().MainActSpinner.setVisibility(View.GONE);
                        MainActivity.getInstance().txtStatus.setText("");
                    }
                }).execute(ReceivedDataFilePath).get();

            }
        };

这是我的 AsyncGETRequestProcess 类,它扩展了 AsyncTask:

 //THE FOLLOWING CLASS RESIDES WITHIN MainActivity Class...
 public static class AsyncGETRequestProcess extends AsyncTask<String, Void, Void> {

        public interface AsyncResponse {
            void processFinish(boolean success);
        }

        public AsyncResponse delegate = null;

        public AsyncGETRequestProcess(AsyncResponse delegate){
            this.delegate = delegate;
        }

        @Override
        protected Void doInBackground(String... strings) {
            //Read the temp file location and create model of 'GET' Data Received.
            GetRequestRoot getRequestRootModel = Core.Helper.GetRootObjFromGetRequestTempFile(strings[0]);

            Boolean responseResult = ServerResponse.ProcessGetRequestResultModel(getRequestRootModel);

            if(responseResult)
            {
                Core.Data.ObjModel = Core.Helper.GetInputFileAsObject();
                if(Core.Data.ObjModel == null){
                    delegate.processFinish(false);
                }
                else{
                    delegate.processFinish(true);
                }
            }else{
                delegate.processFinish(false);
            }

            return null;
        }

        @Override
        protected void onPreExecute(){

        }

        @Override
        protected void onPostExecute(Void result){

        }

    }

我还收到以下编译时错误..

Error:(108, 28) error: processFinish(boolean) in cannot implement processFinish(boolean) in AsyncResponse attempting to assign weaker access privileges; was public

我该如何解决这个问题?我不明白为什么会这样。

最佳答案

您应该公开您的方法 processFinish:

           new AsyncGETRequestProcess(new AsyncGETRequestProcess.AsyncResponse(){
                  //THE ABOVE ERROR HAPPENS HERE... processFinish
                  @Override
                  public void processFinish(boolean success){
                  ^^^^^^

默认情况下所有接口(interface)方法都是公共(public)的

关于java - Android AsyncTask 错误,试图分配较弱的访问权限。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35366814/

相关文章:

android - 从哪里调用 Google 登录 Activity 中的异步任务?

android - AsyncTask 不调用 onProgressUpdate,onPostExecute

java - log4j.xml 配置仅用于调试

java - 修改当前代码以在 > 21 时拒绝用户输入

java - 重置按钮数组后无法更改java按钮颜色

java - 如何将 XML 文档作为参数传递给 java (oracle xdk) 中的 XSL 转换?

android - 加载另一个 fragment 时, fragment 数据变为空

Android onOverrideUrlLoading 基于javascript返回值

Android AsyncTask 和线程

java - 无法构建库项目 Bintray Gradle - ClassNotFoundException