【问题标题】:Android AsyncTask error, attempting to assign weaker access privileges.Android AsyncTask 错误,试图分配较弱的访问权限。
【发布时间】:2016-02-12 15:52:56
【问题描述】:

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

'processFinish(Boolean)' in '匿名类派生自 MainActivity.AsyncGETRequestProcess.AsyncResponse' 与 'processFinish(布尔值)'在 MainActivity.AsyncGETRequestProcess.AsyncResponse';试图 分配较弱的访问权限('packageLocal');是公开的。

我想要完成的是,在收到来自 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 Class,它扩展了 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 试图分配较弱的访问权限;曾是 公开的

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

【问题讨论】:

  • 你不见了public
  • @Ferrybig 这就是我一直在阅读的内容,但我试图公开却什么也没有。

标签: java android android-asynctask


【解决方案1】:

您应该公开您的方法 processFinish:

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

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

【讨论】:

  • 哦,天哪...我一直这样做,但看到整个方法错误地突出显示.. 我从来没有费心将鼠标悬停在上面,发现我只是错过了一个 try/catch!叹息……
猜你喜欢
  • 2012-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
相关资源
最近更新 更多