还有其他相关问题,但它们没有解决我的情况(它们的错误代码与某种回收和/或客户端代码的错误转换调用有关)。
我的情况比较复杂。
我有一些代码,用户可以在其中提取照片库。
问题是,它在我拥有的 7 部手机上运行良好,都运行 API 19+。
但是我有一个运行 API 17 的 Google Nexus 4.3。我得到了这个崩溃日志,其中没有我的代码,只有库代码。如果您能建议我如何编写工作代码,我会全神贯注:
FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
at android.widget.GridView.onMeasure(GridView.java:1042)
at android.view.View.measure(View.java:15848)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
at android.view.View.measure(View.java:15848)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:477)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:15848)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5008)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
at android.view.View.measure(View.java:15848)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1905)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1104)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1284)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
更新
我的违规课程是这样的:
//Special class that works with the UIL
//The holder gets re-used and gets the new properties from this
static class ReusableGridViewView extends FrameLayout
{
public ImageView imageView;
public ProgressBar progressBar;
public ReusableGridViewView(Context context)
{
super(context);
setLayoutParams(new LayoutParams((int)(0.325* ViewHelper.screenWidthPX(context)),(int)(0.325* ViewHelper.screenWidthPX(context))));
imageView = new ImageView(context);
progressBar = new ProgressBar(context);
addView(imageView);
addView(progressBar);
}
}
我正在使用 Ultimate Image Loader 库,这是使用上述类的代码。
//I do NOT call this directly, the listview decides when re use a convert view and passes it accordingly
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
final ViewHolder holder;
View view = convertView;
if (view == null)
{
view = new ReusableGridViewView(parent.getContext());
holder = new ViewHolder();
assert view != null;
holder.imageView = ((ReusableGridViewView)view).imageView;
holder.progressBar = ((ReusableGridViewView)view).progressBar;
holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
//System.out.println(" " + holder + " ||| " + holder.imageView);
ImageLoader.getInstance()
.displayImage(IMAGE_URLS[position], holder.imageView, options, new SimpleImageLoadingListener()
{
@Override
public void onLoadingStarted(String imageUri, View view)
{
holder.progressBar.setProgress(0);
holder.progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason)
{
holder.progressBar.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage)
{
holder.progressBar.setVisibility(View.GONE);
}
}, new ImageLoadingProgressListener()
{
@Override
public void onProgressUpdate(String imageUri, View view, int current, int total)
{
holder.progressBar.setProgress(Math.round(100.0f * current / total));
}
});
//set all as unselected
((ReusableGridViewView) view).removeSelectionBorder();
for(int i = 0; i < SELECTED_IMAGES.length; i++)
{
if(SELECTED_IMAGES[i] == position)
{
//set cell to selected
((ReusableGridViewView) view).addSelectionBorder();
}
}
return view;
}