Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.ClassCastException:android.view.ViewGroup$LayoutParams不能强制转换为android.widget.Gallery$LayoutParams_Android_Android Linearlayout_Android Relativelayout - Fatal编程技术网

java.lang.ClassCastException:android.view.ViewGroup$LayoutParams不能强制转换为android.widget.Gallery$LayoutParams

java.lang.ClassCastException:android.view.ViewGroup$LayoutParams不能强制转换为android.widget.Gallery$LayoutParams,android,android-linearlayout,android-relativelayout,Android,Android Linearlayout,Android Relativelayout,我正在尝试在我的应用程序中添加Fancycoverflow,它可以很好地处理静态图像,如中所示 但我在适配器中做了一些更改,我尝试运行我的应用程序,它崩溃并显示以下错误 FATAL EXCEPTION: main java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.Gallery$LayoutParams at android.widg

我正在尝试在我的应用程序中添加
Fancycoverflow
,它可以很好地处理静态图像,如中所示

但我在适配器中做了一些更改,我尝试运行我的应用程序,它崩溃并显示以下错误

  FATAL EXCEPTION: main
  java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.Gallery$LayoutParams
    at android.widget.Gallery.setUpChild(Gallery.java:889)
    at android.widget.Gallery.makeAndAddView(Gallery.java:858)
    at android.widget.Gallery.layout(Gallery.java:665)
    at android.widget.Gallery.onLayout(Gallery.java:357)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1441)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
    at android.view.View.layout(View.java:14118)
    at android.view.ViewGroup.layout(ViewGroup.java:4467)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2183)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1947)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4872)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
    at android.view.Choreographer.doCallbacks(Choreographer.java:579)
    at android.view.Choreographer.doFrame(Choreographer.java:548)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
    at android.os.Handler.handleCallback(Handler.java:800)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5371)
    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:833)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
    at dalvik.system.NativeStart.main(Native Method)
在示例中,它被给出为

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import at.technikum.mti.fancycoverflow.FancyCoverFlow;
import at.technikum.mti.fancycoverflow.FancyCoverFlowAdapter;
import at.technikum.mti.fancycoverflow.samples.R;

public class ViewGroupExample extends Activity {

    // =============================================================================
    // Supertype overrides
    // =============================================================================

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.layout_inflate_example);

        FancyCoverFlow fancyCoverFlow = (FancyCoverFlow) findViewById(R.id.fancyCoverFlow);
        fancyCoverFlow.setAdapter(new ViewGroupExampleAdapter());
    }

    // =============================================================================
    // Private classes
    // =============================================================================

    private static class ViewGroupExampleAdapter extends FancyCoverFlowAdapter {

        // =============================================================================
        // Private members
        // =============================================================================

        private int[] images = {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6,};

        // =============================================================================
        // Supertype overrides
        // =============================================================================

        @Override
        public int getCount() {
            return images.length;
        }

        @Override
        public Integer getItem(int i) {
            return images[i];
        }

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

        @Override
        public View getCoverFlowItem(int i, View reuseableView, ViewGroup viewGroup) {
            CustomViewGroup customViewGroup = null;

            if (reuseableView != null) {
                customViewGroup = (CustomViewGroup) reuseableView;
            } else {
                customViewGroup = new CustomViewGroup(viewGroup.getContext());
                customViewGroup.setLayoutParams(new FancyCoverFlow.LayoutParams(300, 600));
            }

            customViewGroup.getImageView().setImageResource(this.getItem(i));
            customViewGroup.getTextView().setText(String.format("Item %d", i));

            return customViewGroup;
        }
    }

    private static class CustomViewGroup extends LinearLayout {

        // =============================================================================
        // Child views
        // =============================================================================

        private TextView textView;

        private ImageView imageView;

        private Button button;

        // =============================================================================
        // Constructor
        // =============================================================================

        private CustomViewGroup(Context context) {
            super(context);

            this.setOrientation(VERTICAL);

            this.textView = new TextView(context);
            this.imageView = new ImageView(context);
            this.button = new Button(context);

            LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            this.textView.setLayoutParams(layoutParams);
            this.imageView.setLayoutParams(layoutParams);
            this.button.setLayoutParams(layoutParams);

            this.textView.setGravity(Gravity.CENTER);

            this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            this.imageView.setAdjustViewBounds(true);

            this.button.setText("Goto GitHub");
            this.button.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://davidschreiber.github.com/FancyCoverFlow"));
                    view.getContext().startActivity(i);
                }
            });

            this.addView(this.textView);
            this.addView(this.imageView);
            this.addView(this.button);
        }

        // =============================================================================
        // Getters
        // =============================================================================

        private TextView getTextView() {
            return textView;
        }

        private ImageView getImageView() {
            return imageView;
        }
    }
}
根据我的要求,我改变的是

MyAdapter

private static class ViewGroupExampleAdapter extends FancyCoverFlowAdapter {

 private LayoutInflater inflater;
    public Activity a;
    View vi;
    public ArrayList<HashMap<String, String>> arr;
    public ArrayList<HashMap<String, String>> data;


    public ViewGroupExampleAdapter(Activity homeActivity, ArrayList<HashMap<String, String>> myList) {

        arr = myList;
        a = homeActivity;
        inflater = (LayoutInflater) a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    // =============================================================================
    // Private members
    // =============================================================================

  //  private int[] images = {R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher,};

    // =============================================================================
    // Supertype overrides
    // =============================================================================

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

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        System.out.println("position=" + position);
        return position;
    }

    @Override
    public View getCoverFlowItem(int i, View reuseableView, ViewGroup viewGroup) {
        View vi = reuseableView;
        if (vi == null)
            vi = inflater.inflate(R.layout.create_club_inflate, null);

        TextView date1 = (TextView) vi.findViewById(R.id.txtDate1);
        TextView date = (TextView) vi.findViewById(R.id.txtDate);
        TextView team1_name = (TextView) vi.findViewById(R.id.txtTeamName);
        TextView team2_name = (TextView) vi.findViewById(R.id.txtVanue);
        TextView ground = (TextView) vi.findViewById(R.id.txt_time);

        HashMap<String, String> product = new HashMap<String, String>();
        product = arr.get(i);

        System.out.println("name 1= " + product.get("str_team1_name") + " team 2="
                + product.get("str_team2_obj_name"));
        date1.setText(product.get("str_srs"));
        date.setText(product.get("str_startdt"));
        team1_name.setText(product.get("str_team1_name"));
        team1_name.setAlpha(5000);
        team2_name.setText(product.get("str_team2_obj_name"));
        team2_name.setAlpha(5000);
    //  Typeface font = Typeface.createFromAsset(getAssets(), "TitilliumText22L006.otf");

        int[] color = { Color.rgb(100, 100, 100), Color.rgb(255, 255, 255) };
        float[] color_position = { 0, 1 };
        TileMode tile_mode = TileMode.MIRROR; // or TileMode.REPEAT;
        LinearGradient lin_grad = new LinearGradient(0, 0, 0, 50, color, color_position, tile_mode);
        Shader shader_gradient = lin_grad;
        team1_name.getPaint().setShader(shader_gradient);
        team2_name.getPaint().setShader(shader_gradient);
        //team1_name.setTypeface(font);
    //  team2_name.setTypeface(font);
        ground.setText(product.get("str_grnd"));

        product.get("str_sName");
        product.get("str_team2_obj_sName");


        String first_team_id = product.get("str__team1_id");
        String second_team_id = product.get("str_team2_obj_id");

        switch (first_team_id) {
        case "PAK":
            team1_name.setBackgroundResource(R.drawable.pak);
            break;
        case "UAE":
            team1_name.setBackgroundResource(R.drawable.uae);
            break;
        case "AUS":
            team1_name.setBackgroundResource(R.drawable.aus);
            break;
        case "AFG":
            team1_name.setBackgroundResource(R.drawable.afg);
            break;
        case "6":
            team1_name.setBackgroundResource(R.drawable.ban);
            break;
        case "23":
            team1_name.setBackgroundResource(R.drawable.sco);
            break;
        case "2":
            team1_name.setBackgroundResource(R.drawable.ind);
            break;
        case "WI":
            team1_name.setBackgroundResource(R.drawable.wi);
            break;
        case "13":
            team1_name.setBackgroundResource(R.drawable.nz);
            break;
        case "SL":
            team1_name.setBackgroundResource(R.drawable.sl);
            break;
        case "9":
            team1_name.setBackgroundResource(R.drawable.eng);
            break;
        case "27":
            team1_name.setBackgroundResource(R.drawable.ir);
            break;
        case "11":
            team1_name.setBackgroundResource(R.drawable.rsa);
            break;
        case "ZIM":
            team1_name.setBackgroundResource(R.drawable.zim);
            break;
        case "63":
            team1_name.setBackgroundResource(R.drawable.kol_fl);
            break;
        case "62":
            team1_name.setBackgroundResource(R.drawable.mum_fl);
            break;
        case "58":
            team1_name.setBackgroundResource(R.drawable.chn_fl);
            break;
        case "61":
            team1_name.setBackgroundResource(R.drawable.del_fl);
            break;
        case "65":
            team1_name.setBackgroundResource(R.drawable.pun_fl);
            break;
        case "64":
            team1_name.setBackgroundResource(R.drawable.raj_fl);
            break;
        case "255":
            team1_name.setBackgroundResource(R.drawable.hyd_fl);
            break;
        case "59":
            team1_name.setBackgroundResource(R.drawable.blr_fl);
            break;
        default:
            team1_name.setBackgroundResource(R.drawable.otherflag);
            // h_upcoming.tv_left.setText(str1);
            break;
        }

        // second team

        switch (second_team_id) {
        case "PAK":
            team2_name.setBackgroundResource(R.drawable.pak);
            break;
        case "UAE":
            team2_name.setBackgroundResource(R.drawable.uae);
            break;
        case "AUS":
            team2_name.setBackgroundResource(R.drawable.aus);
            break;
        case "AFG":
            team2_name.setBackgroundResource(R.drawable.afg);
            break;
        case "6":
            team2_name.setBackgroundResource(R.drawable.ban);
            break;
        case "23":
            team2_name.setBackgroundResource(R.drawable.sco);
            break;
        case "2":
            team2_name.setBackgroundResource(R.drawable.ind);
            break;
        case "WI":
            team2_name.setBackgroundResource(R.drawable.wi);
            break;
        case "13":
            team2_name.setBackgroundResource(R.drawable.nz);
            break;
        case "SL":
            team2_name.setBackgroundResource(R.drawable.sl);
            break;
        case "9":
            team2_name.setBackgroundResource(R.drawable.eng);
            break;
        case "27":
            team2_name.setBackgroundResource(R.drawable.ir);
            break;
        case "11":
            team2_name.setBackgroundResource(R.drawable.rsa);
            break;
        case "ZIM":
            team2_name.setBackgroundResource(R.drawable.zim);
            break;
        case "63":
            team2_name.setBackgroundResource(R.drawable.kol_fl);
            break;
        case "62":
            team2_name.setBackgroundResource(R.drawable.mum_fl);
            break;
        case "58":
            team2_name.setBackgroundResource(R.drawable.chn_fl);
            break;
        case "61":
            team2_name.setBackgroundResource(R.drawable.del_fl);
            break;
        case "65":
            team2_name.setBackgroundResource(R.drawable.pun_fl);
            break;
        case "64":
            team2_name.setBackgroundResource(R.drawable.raj_fl);
            break;
        case "255":
            team2_name.setBackgroundResource(R.drawable.hyd_fl);
            break;
        case "59":
            team2_name.setBackgroundResource(R.drawable.blr_fl);
            break;
        default:
            team1_name.setBackgroundResource(R.drawable.otherflag);
            // h_upcoming.tv_left.setText(str1);
            break;
        }

        return vi;

    }
}

      /*  private static class CustomViewGroup extends LinearLayout {

    // =============================================================================
    // Child views
    // =============================================================================

    private TextView textView;

    private ImageView imageView;

    private Button button;

    // =============================================================================
    // Constructor
    // =============================================================================

    private CustomViewGroup(Context context) {
        super(context);

        this.setOrientation(VERTICAL);

        this.textView = new TextView(context);
        this.imageView = new ImageView(context);
        this.button = new Button(context);

        LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        this.textView.setLayoutParams(layoutParams);
        this.imageView.setLayoutParams(layoutParams);
        this.button.setLayoutParams(layoutParams);

        this.textView.setGravity(Gravity.CENTER);

        this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        this.imageView.setAdjustViewBounds(true);

        this.button.setText("Goto GitHub");
        this.button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://davidschreiber.github.com/FancyCoverFlow"));
                view.getContext().startActivity(i);
            }
        });

        this.addView(this.textView);
        this.addView(this.imageView);
        this.addView(this.button);
    }

    // =============================================================================
    // Getters
    // =============================================================================

    private TextView getTextView() {
        return textView;
    }

    private ImageView getImageView() {
        return imageView;
    }
}*/
私有静态类ViewGroupExampleAdapter扩展了FancyOverflowAdapter{
私人充气机;
公共活动a;
视图六;
公共ArrayList arr;
公共阵列列表数据;
public ViewGroupExampleAdapter(活动homeActivity,ArrayList myList){
arr=myList;
a=家庭活动;
充气器=(LayoutInflater)a.getSystemService(Context.LAYOUT\u充气器\u SERVICE);
}
// =============================================================================
//私人成员
// =============================================================================
//私有int[]图像={R.drawable.ic_启动器,R.drawable.ic_启动器,R.drawable.ic_启动器,R.drawable.ic_启动器,R.drawable.ic_启动器,R.drawable.ic_启动器,};
// =============================================================================
//超类型重写
// =============================================================================
@凌驾
public int getCount(){
返回arr.size();
}
@凌驾
公共对象getItem(int位置){
//TODO自动生成的方法存根
返回位置;
}
@凌驾
公共长getItemId(int位置){
//TODO自动生成的方法存根
系统输出打印项次(“位置=”+位置);
返回位置;
}
@凌驾
公共视图getCoverFlowItem(int i、视图重用视图、视图组视图组){
视图vi=可重用视图;
如果(vi==null)
vi=充气机。充气(R.layout.create_club_充气,空);
TextView date1=(TextView)vi.findviewbyd(R.id.txtDate1);
TextView日期=(TextView)vi.findViewById(R.id.txtDate);
TextView team1_name=(TextView)vi.findViewById(R.id.txtTeamName);
TextView团队2_name=(TextView)vi.findViewById(R.id.txtVanue);
TextView地面=(TextView)vi.findViewById(R.id.txt_时间);
HashMap产品=新的HashMap();
产品=arr.get(i);
System.out.println(“name 1=“+product.get”(“str\u team1\u name”)+“team 2=”
+获取(“str_team2_obj_name”);
date1.setText(product.get(“str_srs”);
date.setText(product.get(“str_startdt”);
team1_name.setText(product.get(“str_team1_name”);
团队1_name.setAlpha(5000);
team2_name.setText(product.get(“str_team2_obj_name”);
团队2_名称setAlpha(5000);
//Typeface font=Typeface.createFromAsset(getAssets(),“TitilliumText22L006.otf”);
int[]color={color.rgb(100100100),color.rgb(255,255,255)};
float[]color_position={0,1};
TileMode tile_mode=TileMode.MIRROR;//或TileMode.REPEAT;
LinearGradient lin\u grad=新的LinearGradient(0,0,0,50,颜色,颜色位置,平铺模式);
着色器着色器\梯度=林\梯度;
team1_name.getPaint().setShader(着色器_渐变);
team2_name.getPaint().setShader(着色器_渐变);
//team1_name.setTypeface(字体);
//team2_name.setTypeface(字体);
ground.setText(product.get(“str_grnd”);
产品获取(“stru sName”);
产品获取(“str_team2_obj_sName”);
字符串first_team_id=product.get(“str_team 1_id”);
字符串second_team_id=product.get(“str_team2_obj_id”);
开关(第一队id){
案例“PAK”:
团队1_name.setBackgroundResource(R.drawable.pak);
打破
案例“阿联酋”:
团队1_name.setBackgroundResource(R.drawable.uae);
打破
“澳大利亚”案:
团队1_name.setBackgroundResource(R.drawable.aus);
打破
案例“AFG”:
团队1_name.setBackgroundResource(R.drawable.afg);
打破
案例“6”:
团队1_name.setBackgroundResource(R.drawable.ban);
打破
案例“23”:
团队1_name.setBackgroundResource(R.drawable.sco);
打破
案例“2”:
团队1_name.setBackgroundResource(R.drawable.ind);
打破
案例“WI”:
团队1_name.setBackgroundResource(R.drawable.wi);
打破
案例“13”:
团队1_name.setBackgroundResource(R.dravable.nz);
打破
案例“SL”:
团队1_name.setBackgroundResource(R.drawable.sl);
打破
案例“9”:
团队1_name.setBackgroundResource(R.drawable.eng);
打破
案例“27”:
团队1_name.setBackgroundResource(R.drawable.ir);
打破
案例“11”:
团队1_name.setBackgroundResource(R.drawable.rsa);
打破
案例“ZIM”:
团队1_name.setBackgroundResource(R.drawable.zim);
打破
案例“63”:
团队1\u名称。挫折背景资源(R.drawable.kol\u fl);
打破
案例“62”:
团队1_name.setBackgroundResource(R.drawable.mum_fl);
打破
案例“58”:
团队1\u名称。挫折资源(R.drawable.chn\u fl);
打破
案例“61”:
团队1_name.setBackgroundResource(R.drawable.del_fl);
打破
案例“65”:
团队1_name.setBackgroundResource(R.drawable.pun_fl);
打破
案例“64”:
团队1_name.setBackgroundResource(R.drawable.raj_fl);
打破
案例“255”:
团队1\u名称。挫折资源(R.drawable.hyd\u fl);
打破
案例“59”:
团队1\u名称。挫折资源(R.d