ClassCastException android.view.viewgroup.$ layoutParam

rit*_*tta 4 android android-widget android-layout

 TextView txt=new TextView(productlist.this);
            txt.setText(author.get(groupPosition));
            TextView txt1=new TextView(productlist.this);
            txt1.setText(price.get(groupPosition));
            txt.setLayoutParams(new LayoutParams(70, LayoutParams.WRAP_CONTENT));  
            txt1.setLayoutParams(new LayoutParams(70,LayoutParams.WRAP_CONTENT));
            LinearLayout ll=new LinearLayout(productlist.this);
            ll.setOrientation(LinearLayout.HORIZONTAL);
            ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));  
           // ll.setGravity(Gravity.CENTER);  
            ll.addView(txt);  
            ll.addView(txt1);  

            return ll;
Run Code Online (Sandbox Code Playgroud)

嗨,这是可扩展的组视图的代码片段,ListView它给出了错误:

java.lang.ClassCastException android.view.viewgroup.$ layoutParam

Gal*_*lal 13

确保导入正确的LayoutParams.

  • LinearLayout的android.widget.LinearLayout.LayoutParams
  • TextView的android.view.ViewGroup.LayoutParams