I am trying the apply this example to my project but I am getting the following error:
Error:(26, 33) error: cannot find symbol method findViewById(int)
This is how my code looks like:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.AsyncTask;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView display = (TextView) findViewById(R.id.textView1);
display.setText("Hello Android!");
Connect myConnect = new Connect();
myConnect.execute();
}
}
class Connect extends AsyncTask<Void, Void, Integer> {
TextView Text1 = (TextView) findViewById(R.id.textView1);
@Override
protected void onPreExecute(){
}
@Override
protected Integer doInBackground(Void... params) {
return 0;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onPostExecute(0);
Text1.setText("Text Changed");
}
}
- What am I missing here?
- How can I reference the TextView through the AsyncTask?