Hey guys,

This is my first stab at programmable graphics on Android and I'm
running into some LifeCycle issues (I think). If any of the gurus on
the board could point me in the right direction, I'd appreciate it.
Here's the scenario:

1. Dialog box that contains a GridView.
2. GridView contains an ImageAdapter (extends BaseAdapter)
3. ImageAdapter contains an ImageView, which is returned on getView,
handing the recycling based on the convertView parameter. It's about
95% of the 
http://developer.android.com/resources/tutorials/views/hello-gallery.html
ImageAdapter.
4. The ImageView is either an ImageResource or an ImageDrawable. If
the ImageResource for the given element is available, it uses that. If
not, it constructs a custom Drawable that's a filled rectangle with
the name of the element in text.

I recently added the custom drawable portion, so I believe that's part
of my issue, as it was working previously.

The behavior I'm seeing is that when the Dialog is 1st displayed,
everyhting happens as expected; however, when I close the dialog and
open it back up, the application crashes with the following stack:

<pre>
java.lang.NullPointerException
        at android.view.ViewConfiguration.get(ViewConfiguration.java:211)
        at android.view.View.<init>(View.java:1814)
        at android.widget.ImageView.<init>(ImageView.java:103)
        at com.federated.droid.moose.input.BrandSelectionGrid
$ImageAdapter.getView(BrandSelectionGrid.java:154)
        at android.widget.AbsListView.obtainView(AbsListView.java:1315)
        at android.widget.GridView.onMeasure(GridView.java:932)
        at android.view.View.measure(View.java:8173)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:
3132)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
        at android.view.View.measure(View.java:8173)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
        at android.view.View.measure(View.java:8173)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:
3132)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
        at android.view.View.measure(View.java:8173)
        at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
        at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4627)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
        at dalvik.system.NativeStart.main(Native Method)
</pre>

The getView method looks like this:

<pre>
public View getView( int position, View convertView, ViewGroup
parent )
{
        if (convertView == null)
        { // if it's not recycled, initialize some attributes
                imageView = new ImageView( mContext );
                imageView.setLayoutParams( new GridView.LayoutParams( 
thumbHeightPx,
thumbWidthPx ) );
                imageView.setScaleType( ImageView.ScaleType.CENTER_CROP );
        
imageView.setBackgroundResource( R.drawable.acc_brand_select_background );
        }
        else
        {
                imageView = (ImageView) convertView;
        }

        Brand theBrand = Moose.getUser().getBrandList().get( position );
        BrandType type =
BrandResourceDictionary.getBrandById( theBrand.getId() );

        if( type == null )
        {
                BrandThumbnail brandThumb = new BrandThumbnail( theBrand );
                imageView.setImageDrawable( brandThumb );
                imageView.setOnClickListener( new
BrandImageClick( theBrand.getId() ) );
        }
        else
        {
                imageView.setImageResource( type.getThumbResource() );
                imageView.setOnClickListener( new BrandImageClick( type.getId() 
) );
        }

        if (position < imageViewList.size())
        {
                imageViewList.set( position, this );
        }
        else
        {
                imageViewList.add( this );
        }

        return imageView;
}
</pre>

With the error coming on line 154: imageView = new
ImageView( mContext ); (Line 5 in the pasted code above)

Why does it crash when displaying the second time? Am I fundamentally
missing a part of the lifecycle of this object? Any other advice you
can give me?

Thanks for reading throgh the post! I really appreciate any help I can
get!

Thanks,

Evan Ruff, Atlanta

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to