1

I'm getting this error "No enclosing instance of type Datagetter is accessible. Must qualify the allocation with an enclosing instance of type Datagetter (e.g. x.new A() where x is an instance of Datagetter)." and my code is

public static void initializeValues
    (String _NAMESPACE , String _URL , String _SOAP_ACTION , 
String _METHOD_NAME , String _PARAM_NAME , String _PARAM_VALUE)

    {
        NAMESPACE = _NAMESPACE ;
        URL = _URL ;
        SOAP_ACTION = _SOAP_ACTION ;
        METHOD_NAME = _METHOD_NAME ;
        PARAM_NAME = _PARAM_NAME ;
        PARAM_VALUE = _PARAM_VALUE ;
        TAG = "Name of log" ;


        AsyncCallWS task = new AsyncCallWS();
        //Call execute
         task.execute();

    }

AsyncCallWS

public class AsyncCallWS extends AsyncTask<String, Void, Void> {

        protected Void doInBackground(String... params) {
            Log.i(TAG, "doInBackground");
            getDataFromWebservice();
            return null;
        }


        protected void onPostExecute(Void result) {
            Log.i(TAG, "onPostExecute");
        //    tv.setText(fahren + "° F");
        }


        protected void onPreExecute() {
            Log.i(TAG, "onPreExecute");
         //   tv.setText("Calculating...");
        }


        protected void onProgressUpdate(Void... values) {
            Log.i(TAG, "onProgressUpdate");
        }

    }
Nambi
  • 11,944
  • 3
  • 37
  • 49
Esat IBIS
  • 381
  • 1
  • 5
  • 19

3 Answers3

6

The method where you are instantiating the asynctask is static. However, the AsyncCallWS seems to be a non-static inner class. Non-static inner classes hold a reference to the parent and therefore cannot be accessed without the parent object.

Probably your async task should be declared static - most often having an asynctask non-static is a programming error.

laalto
  • 150,114
  • 66
  • 286
  • 303
1

Because you creating the new object in "static" method. You should add the modifier "static" to AsyncCallWS class such as :

public static class AsyncCallWS extends AsyncTask<String, Void, Void> { ...... } 
Avijit
  • 3,834
  • 4
  • 33
  • 45
soxfmr
  • 58
  • 7
0

Change your method signature

public static void initializeValues()

to

public void initializeValues()
ravindra.kamble
  • 1,023
  • 3
  • 11
  • 20