views:

61

answers:

0

I received the following error when attempting to switch between a ProgressBar and an Image using a viewSwitcher:

07-30 18:08:00.627: ERROR/AndroidRuntime(307): Caused by: java.lang.NullPointerException
07-30 18:08:00.627: ERROR/AndroidRuntime(307):     at android.view.ViewGroup.addView(ViewGroup.java:1815)
07-30 18:08:00.627: ERROR/AndroidRuntime(307):     at android.view.ViewGroup.addView(ViewGroup.java:1802)
07-30 18:08:00.627: ERROR/AndroidRuntime(307):     at com.romcessed.romsearch.activities.RomDetailActivity$LoadImageViewsTask.intializeSwitchers(RomDetailActivity.java:161)

Here is the code that caused the error:

//Place indeterminate progress bars for our ImageViews until computation is complete
switcherTask = new LoadImageViewsTask();
switcherTask.intializeSwitchers();
switcherTask.execute((Void) null);

.
..
...

void intializeSwitchers(){
    captchaSwitcher = new ViewSwitcher(RomDetailActivity.this);
    gallerySwitcher = new ViewSwitcher(RomDetailActivity.this);

    /*Line that caused error */ 
    captchaSwitcher.addView((ProgressBar)findViewById(R.layout.indeter));
    /*                       */
    gallerySwitcher.addView(findViewById(R.layout.indeter));

    captchaSwitcher.addView(iv_Captcha);
    gallerySwitcher.addView(gal_Screenshots);
}

Here is indeter.xml:

<?xml version="1.0" encoding="utf-8"?>
    <ProgressBar
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/progressbar"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerVertical="true" />