简体   繁体   中英

error: cannot find symbol class AsyncCallWS Android

I'm trying to rewrite the application in this, in Android Studio link , which is written in Eclipse. There are two problems, first problem is there is this line in the project :

import com.example.webserviceactivity.R; 

I couldn't write this one on Android Studio. The second problem is, in this part of the code :

b = (Button) findViewById(R.id.button1);
        //Button Click Listener
        b.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                //Check if Celcius text control is not empty
                if (et.getText().length() != 0 && et.getText().toString() != "") {
                    //Get the text control value
                    celcius = et.getText().toString();
                    //Create instance for AsyncCallWS
                    AsyncCallWS task = new AsyncCallWS();
                    //Call execute 
                    task.execute();
                //If text control is empty
                } else {
                    tv.setText("Please enter Celcius");
                }
            }
        });

I have this error :

error: cannot find symbol class AsyncCallWS Android in this part :

AsyncCallWS task = new AsyncCallWS();

How can I solve these problems? Thanks.

On the link you post, I see a class like below. Create this class in your project before using it.

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
        @Override
        protected Void doInBackground(String... params) {
            Log.i(TAG, "doInBackground");
            getFahrenheit(celcius);
            return null;
        }

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

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

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

    }

First you have to remove import statement from ur code or replace com.example.webserviceactivity with ur package name.

Second copy AsyncCallWS class from given link and put on your activity class or create same class on ur project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM