Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Tunde Adegoroye
20,597 PointsFinishing Our AsyncTask code challenge
Im currently on the 2nd step on this code challenge:
Inside 'onPostExecute()', set the member variable 'mStatus' to the value passed into 'onPostExecute()'. Then call the 'updateStatusLabel()' method of 'CustomActivity'.
i am using this
import android.os.AsyncTask;
import android.os.Bundle;
public class CustomActivity extends Activity {
public String mStatus;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom);
CustomAsyncTask task = new CustomAsyncTask();
task.execute();
}
protected void updateStatusLabel() {
super.updateStatusLabel();
}
protected class CustomAsyncTask extends AsyncTask<Object, Void, String> {
@Override
protected String doInBackground(Object... params) {
// Imagine this is some code to do some work
return "Done!";
}
@Override
protected void onPostExecute(String result){
mStatus = result.updateStatusLabel();
}
}
But i can not see where i am getting it wrong
help please it's saying
Bummer! Compilation Error! Check your syntax and make sure you are 1) setting 'mStatus' correctly and 2) calling 'updateStatusLabel()' correctly.
3 Answers
Ben Jakuben
Treehouse TeacherLet's take a look at the line you added to onPostExecute:
mStatus = result.updateStatusLabel();
On the right side, the way this is written, you are trying to call the updateStatusLabel() method of the result variable, which is a String. That method isn't a String method, though. It's a local method from the CustomActivity class we are working in.
mStatus is a String variable, so you can simply assign the result String variable to it.
Then on a new line you just want to call the method updateStatusLabel() all by itself. Since it's defined in the CustomActivity class (which contains all of our code, even the CustomAsyncTask) and doesn't return anything, you can simply call it on its own.
Allan Evans
9,501 PointsThanks for answering that, I was a little confused on the "updateStatusLabel()" as well.
x y
1,908 PointsCompilation Error! Verify that the 'onPostExecute()' method starts with 'protected void' and actually returns a String inside the curly braces, and check the rest of your syntax
Ben Jakuben
Treehouse TeacherDid you ever get this working? If not, paste your code in a reply and we'll get you there. :)
Dave Buda
5,157 Pointsprotected void onPostExecute(String result){ mStatus = result; updateStatusLabel();
Nick Pettit
Treehouse TeacherNick Pettit
Treehouse TeacherHi Tunde Adegoroye,
I'm not sure what the answer is here, but I've pinged Ben Jakuben, our Andrioid teacher. He should be able to help you out. :)