ClassCastException at Gallery.setLayoutParams?
I am create a base adapter for a Gallery.
I am using this method to override getView().
But i keep getting this error at the LayoutParam's code.
10-02 01:14:32.543: ERROR/AndroidRuntime(839): FATAL EXCEPTION: main
10-02 01:14:32.543: ERROR/AndroidRuntime(839): java.lang.ClassCastException: android.widget.Gallery$LayoutParams
10-02 01:14:32.543: ERROR/AndroidRuntime(839): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:659)
10-02 01:14:32.543: ERROR/AndroidRuntime(839): at android.widget.LinearLayout.onMeasure(LinearLayout.java:311)
10-02 01:14:32.543: ERROR/AndroidRunt开发者_运维百科ime(839): at android.view.View.measure(View.java:8313)
10-02 01:14:32.543: ERROR/AndroidRuntime(839): at android.view.ViewGroup.measureChild(ViewGroup.java:3109)
Here is my method..
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.lazyitemt, null);
ImageView image=(ImageView)vi.findViewById(R.id.image);
image.setLayoutParams(new Gallery.LayoutParams(250, 250));
imageLoader.DisplayImage(data[position], activity, image);
return vi;
}
Is the view child with id image
inside of a Gallery
? According to the stack trace, it looks like the child is trying to be positioned by a LinearLayout
, which can not use the Gallery.LayoutParams
params. Are you sure that there's only one View
in your layout that is identified by id image
, and are you sure that this view is not getting somehow moved from a Gallery
into a LinearLayout
?
精彩评论