Reputation: 39
I had a NullPointerException when I try to set ProgessBar to visible in onPreExecute AsyncTask (mProgressBar.setVisibility(View.VISIBLE);)
. I don't know what went wrong! Thanks you all!
<ProgressBar
android:id="@+id/pb_featured_game_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
public class MainActivity extends Activity {
...
private ProgressBar mProgressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
new FetchGamesTask().execute();
private class FetchGamesTask extends
AsyncTask<Integer, Integer, List<GameInfo>> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
mProgressBar = (ProgressBar)findViewById(R.id.pb_featured_game_progress);
mProgressBar.setVisibility(View.VISIBLE);
}
Upvotes: 0
Views: 191
Reputation: 5568
Before you call the execute on your FetchGamesTask
, you should associate the main view with the xml file.
Like this
protected void onCreate(Bundle savedInstanceState) {
// the OS will inflate the main_activity.xml
// file and use it for this activity
setContentView(R.layout.main_activity);
new FetchGamesTask().execute();
Upvotes: 4