gpt4 book ai didi

android - ClassCastException : android. 部件.LinearLayout$LayoutParams

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:50:28 27 4
gpt4 key购买 nike

所以我在 FinderActivity.class 中执行适配器时遇到此错误。

public class FinderActivity extends ListActivity
{
private List<String> itemsearchoptions = Arrays.asList(
new String[]
{
"Search Service Center","Search Showroom",
"Area Surveillance", "Nearest OAC Offices"
});
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.finder);


getListView().setAdapter(new FinderListAdapter(this, this.itemsearchoptions));//cause of error


}

这是我的 FinderAdapter 类:

public class FinderListAdapter extends BaseAdapter
{
Context context;
LayoutInflater inflater;
private int[]icons =
{
R.drawable.icon_service_center,
R.drawable.icon_car_showroom,
R.drawable.icon_radar,
R.drawable.icon_office
};
private List<String>options = null;

public FinderListAdapter(Context paramContext, List<String>paramList)
{
this.context = paramContext;
this.options = paramList;
this.inflater = LayoutInflater.from(paramContext);
}

@Override
public int getCount()
{
return this.options.size();
}

@Override
public Object getItem(int paramInt)
{
return this.options.get(paramInt);
}

@Override
public long getItemId(int paramInt)
{
return paramInt;
}


@Override
public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
{
String str = (String)this.options.get(paramInt);

if(paramView == null)
{

}
else
{

return paramView;
}
return paramViewGroup;
}
public boolean isEmpty()
{
return (this.options == null)||(this.options.size()==0);
}

private static class ViewHolder
{
ImageView finderIcon;
TextView finderText;
}
}

我在项目列表上使用了LinearLayout

我读过几个关于这个错误的类似问题,但还没有完全理解这个概念。所以任何帮助将不胜感激。谢谢

已编辑:抱歉忘记了堆栈跟踪

07-08 15:31:42.380: E/AndroidRuntime(4550): FATAL EXCEPTION: main
07-08 15:31:42.380: E/AndroidRuntime(4550): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.widget.ListView.measureScrapChild(ListView.java:1166)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.widget.ListView.measureHeightOfChildren(ListView.java:1248)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.widget.ListView.onMeasure(ListView.java:1158)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.view.View.measure(View.java:15525)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.view.View.measure(View.java:15525)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.view.View.measure(View.java:15525)
07-08 15:31:42.380: E/AndroidRuntime(4550): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)

最佳答案

在您的导入中使用 android.widget.AbsListView.LayoutParams 而不是 android.widget.LinearLayout.LayoutParams

ClassCastException 堆栈跟踪非常具有描述性......

关于android - ClassCastException : android. 部件.LinearLayout$LayoutParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17523256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com