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

时间:2016-02-12 15:52:56

标签: java android android-asynctask

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

  

'processFinish(Boolean)'在'Anonymous类中派生自   MainActivity.AsyncGETRequestProcess.AsyncResponse'冲突   'processFinish(Boolean)'中   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){

        }

    }

我也得到以下编译时错误..

  

错误:(108,28)错误:processFinish(boolean)in无法实现processFinish(boolean)in   AsyncResponse尝试分配较弱的访问权限;是   公共

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

1 个答案:

答案 0 :(得分:2)

你应该让你的方法processFinish public:

router.NotFound = http.FileServer(http.Dir("./public"))

所有接口方法默认为public