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 trialJavier Briones
Front End Web Development Techdegree Student 29,674 PointsAdding a swipe-to-refresh gesture task 3 of 4
Hello, I've been trying and trying but I just can't figure out this code challenge. Here's my code:
import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
public class MainActivity extends ListActivity {
/*
* Some code has been omitted for brevity
*/
public SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.refreshLayout); mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public OnRefreshListener mOnRefreshListener = new OnRefreshListener() {
@Override
public void onRefresh() {
// Code that refreshes the content in the layout...
}
};
}
And here's the error that I get:
./MainActivity.java:11: expected mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ ./MainActivity.java:11: expected mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ ./MainActivity.java:11: cannot find symbol symbol : class mOnRefreshListener location: class MainActivity mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ ./MainActivity.java:11: package mSwipeRefreshLayout does not exist mSwipeRefreshLayout.setOnRefreshListener(mOnRefreshListener); ^ JavaTester.java:72: cannot find symbol symbol : variable mRefreshLayout location: class MainActivity else if (activity.mRefreshLayout == null) { ^ JavaTester.java:83: cannot find symbol symbol : variable mRefreshLayout location: class MainActivity if (activity.mRefreshLayout.isWrongListenerUsed) { ^ JavaTester.java:86: cannot find symbol symbol : variable mRefreshLayout location: class MainActivity else if (!activity.mRefreshLayout.isSetOnRefreshListenerCalled) { ^ 7 errors
3 Answers
Timothy Boland
18,237 Points mRefreshLayout.setOnRefreshListener(mOnRefreshListener);
Ajay Maheshwari
Courses Plus Student 6,423 PointsFinally i figure out this problem method must be call in oncreate()
Ajay Maheshwari
Courses Plus Student 6,423 PointsI got same issue
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
public class MainActivity extends ListActivity {
public SwipeRefreshLayout mRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.refreshLayout);
mRefreshLayout.setOnRefreshListener(mOnRefreshListener);
/*
* Some code has been omitted for brevity
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public OnRefreshListener mOnRefreshListener = new OnRefreshListener() {
@Override
public void onRefresh() {
// Code that refreshes the content in the layout...
}
};
}
Timothy Boland
18,237 PointsTimothy Boland
18,237 PointsDid you figure it out Javier? Or are you still stuck?