精华内容
下载资源
问答
  • linearlayout报错
    2014-10-20 21:02:00

    ============问题描述============


    	@Override
    
    	public View getView(int position, View convertView, ViewGroup parent) {
    
    		// TODO Auto-generated method stub
    
    		convertView = null;
    
    		
    
    		List<Map<String, Object>> _row = listItems.get(position);
    
    		
    
    		LinearLayout.LayoutParams _llp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT);
    
    		LinearLayout _ll = new LinearLayout(context);
    
    		_ll.setOrientation(LinearLayout.HORIZONTAL);
    
    		_ll.setLayoutParams(_llp);
    
    		
    
    		for(int i=0; i<_row.size(); i++) {
    
    			Map<String, Object> _cell = _row.get(i);
    
    			
    
    			LinearLayout.LayoutParams _cellP = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT, Float.parseFloat(_cell.get("weight").toString()));
    
    			
    
    			EditText _ed = new EditText(context);
    
    			_ed.setText(_cell.get("value").toString());
    
    			
    
    			if(_cell.get("type").equals("text"))
    
    				_ed.setFilters(setEditable());
    
    			
    
    			_ll.addView(_ed, _cellP);
    
    		}
    
    		
    
    		
    
    		return _ll;
    
    	}


    错误信息是:java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

    在DDMS里面也没有具体定位哪里错了,逐步调试在return那里出错了,求解?

    ============解决方案1============


      LinearLayout.LayoutParams _llp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT);
    这句代码导致的错误哦

    ============解决方案2============


    因为你的这个LinearLayout是放在一个ListView中(ListView是AbsListView的子类),所以LinearLayout.setLayoutParameters()中应该放AbsListView.LayoutParameter这个类的对象。

    转载于:https://www.cnblogs.com/hugangyan86/p/4038716.html

    更多相关内容
  • <LinearLayout android:layout_width="0dp" android:layout_weight="5" android:layout_height="35dp" android:layout_gravity="center" android:layout_marginLeft="10dp" android:orientation="horizontal" ...
  • 在应用中创建LinearLayout布局文件时报错: The following classes could not be found: - android.support.v7.internal.app.WindowDecorActionBar (Fix Build Path, Create Class) Tip: Try

    android刚入手,使用android studio 1.4

    在应用中创建LinearLayout布局文件时报错:

    The following classes could not be found:
    - android.support.v7.internal.app.WindowDecorActionBar (Fix Build Path, Create Class)
    Tip: Try to build the project.

    修改styles.xml文件里AppTheme的parent,在前面加上Base.


    新建的项目默认:"Theme.AppCompat.Light.DarkActionBar"

    修改后


    展开全文
  • android.widget.LinearLayout; /** * Created by Kodulf on 2016/3/17. */ public class RootLinearLayout extends LinearLayout { public RootLinearLayout(Context context) { super (context); }...
    03-17 17:32:58.164 30209-30209/? E/AndroidRuntime: Process: tech.androidstudio.dispatchdemo, PID: 30209
    03-17 17:32:58.164 30209-30209/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{tech.androidstudio.dispatchdemo/tech.androidstudio.dispatchdemo.MainActivity}: android.view.InflateException: Binary XML file line #3: Error inflating class tech.androidstudio.dispatchdemo.RootLinearLayout
    03-17 17:32:58.164 30209-30209/? E/AndroidRuntime:   Caused by: android.view.InflateException: Binary XML file line #3: Error inflating class tech.androidstudio.dispatchdemo.RootLinearLayout
    03-17 17:32:58.164 30209-30209/? E/AndroidRuntime:     at tech.androidstudio.dispatchdemo.MainActivity.onCreate(MainActivity.java:11)

    03-17 17:32:58.164 30209-30209/? E/AndroidRuntime:     at tech.androidstudio.dispatchdemo.MainActivity.onCreate(MainActivity.java:11) 



    原因 :缺少构造方法:RootLinearLayout(Context context, AttributeSet attrs)

    View(Context ct,AttributeSet set)这个构造在布局xml文件中创建控件的时候自动的调用,如果自定义控件没有这个构造方法,就会抱错。这个含有AttributeSet 的构造方法,应用于布局创建控件,这个AttribteSet attrs 就是XML里面的属性,通过这个属性传给控件.不然控件怎么知道高度时多少,宽度是多少,

     
    
     
    
    解决方法
    添加构造方法:RootLinearLayout(Context context, AttributeSet attrs)

    package tech.androidstudio.dispatchdemo;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.widget.LinearLayout;
    
    /**
     * Created by Kodulf on 2016/3/17.
     */
    public class RootLinearLayout extends LinearLayout {
        public RootLinearLayout(Context context) {
            super(context);
        }
    
        //TODO 一定不能缺少这个构造方法,不然会报错
        public RootLinearLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            int action = ev.getAction();
            switch (action){
                case MotionEvent.ACTION_DOWN:
                    Log.d("Kodulf","RootLinearLayout ACTION_DOWN");
                    break;
            }
            return super.dispatchTouchEvent(ev);
        }
    }
    


    展开全文
  • 我在stackoverflow上发现了自定义LinearLayout的这个例子,但是当我尝试运行它时会抛出错误,有人能找到它的错误吗?自定义LinearLayout:package com.example.androidapp.widgets;import android.content.Context;...

    我在stackoverflow上发现了自定义LinearLayout的这个例子,但是当我尝试运行它时会抛出错误,有人能找到它的错误吗?

    自定义LinearLayout:

    package com.example.androidapp.widgets;

    import android.content.Context;

    import android.content.res.TypedArray;

    import android.util.AttributeSet;

    import android.view.View;

    import android.view.animation.Animation;

    import android.view.animation.Transformation;

    import android.widget.LinearLayout;

    public class ExpandablePanel extends LinearLayout {

    private final int mHandleId;

    private final int mContentId;

    private View mHandle;

    private View mContent;

    private boolean mExpanded = true;

    private int mCollapsedHeight = 0;

    private int mContentHeight = 0;

    public ExpandablePanel(Context context) {

    this(context, null);

    }

    public ExpandablePanel(Context context, AttributeSet attrs) {

    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs,

    R.styleable.ExpandablePanel, 0, 0);

    // How high the content should be in "collapsed" state

    mCollapsedHeight = (int) a.getDimension(

    R.styleable.ExpandablePanel_collapsedHeight, 0.0f);

    int handleId = a.getResourceId(R.styleable.ExpandablePanel_handle, 0);

    if (handleId == 0) {

    throw new IllegalArgumentException(

    "The handle attribute is required and must refer "

    + "to a valid child.");

    }

    int contentId = a.getResourceId(R.styleable.ExpandablePanel_content, 0);

    if (contentId == 0) {

    throw new IllegalArgumentException(

    "The content attribute is required and must refer "

    + "to a valid child.");

    }

    mHandleId = handleId;

    mContentId = contentId;

    a.recycle();

    }

    @Override

    protected void onFinishInflate() {

    super.onFinishInflate();

    mHandle = findViewById(mHandleId);

    if (mHandle == null) {

    throw new IllegalArgumentException(

    "The handle attribute is must refer to an"

    + " existing child.");

    }

    mContent = findViewById(mContentId);

    if (mContent == null) {

    throw new IllegalArgumentException(

    "The content attribute is must refer to an"

    + " existing child.");

    }

    mHandle.setOnClickListener(new PanelToggler());

    }

    @Override

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    if (mContentHeight == 0) {

    // First, measure how high content wants to be

    mContent.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED);

    mContentHeight = mContent.getMeasuredHeight();

    }

    // Then let the usual thing happen

    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    }

    private class PanelToggler implements OnClickListener {

    @Override

    public void onClick(View v) {

    Animation a;

    if (mExpanded) {

    a = new ExpandAnimation(mContentHeight, mCollapsedHeight);

    } else {

    a = new ExpandAnimation(mCollapsedHeight, mContentHeight);

    }

    a.setDuration(500);

    mContent.startAnimation(a);

    mExpanded = !mExpanded;

    }

    }

    private class ExpandAnimation extends Animation {

    private final int mStartHeight;

    private final int mDeltaHeight;

    public ExpandAnimation(int startHeight, int endHeight) {

    mStartHeight = startHeight;

    mDeltaHeight = endHeight - startHeight;

    }

    @Override

    protected void applyTransformation(float interpolatedTime,

    Transformation t) {

    android.view.ViewGroup.LayoutParams lp = mContent.getLayoutParams();

    lp.height = (int) (mStartHeight + mDeltaHeight * interpolatedTime);

    mContent.setLayoutParams(lp);

    }

    @Override

    public boolean willChangeBounds() {

    // TODO Auto-generated method stub

    return true;

    }

    }

    }

    res>值> attrs.xml

    main.xml中:

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:cl="http://schemas.android.com/apk/lib/com.example.androidapp.widgets"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:orientation="vertical" >

    android:orientation="vertical"

    android:layout_height="wrap_content"

    android:layout_width="fill_parent"

    cl:handle="@+id/expand"

    cl:content="@+id/value"

    cl:collapsedHeight="50dip">

    android:id="@id/value"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:maxHeight="50dip"

    />

    android:id="@id/expand"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="More" />

    活动类:

    package com.example.androidapp.widgets;

    import android.app.Activity;

    import android.os.Bundle;

    public class GoodPanelsActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    }

    }

    LogCat错误:

    FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start

    activity

    ComponentInfo{com.example.androidapp.widgets/com.example.androidapp.widgets.GoodPanelsActivity}:

    android.view.InflateException: Binary XML file line #9: Error

    inflating class com.example.androidapp.widgets.ExpandablePanel

    编辑:更多来自LogCat

    java.lang.reflect.InvocationTargetException at

    java.lang.reflect.Constructor.constructNative(Native Method) at

    java.lang.reflect.Constructor.newInstance(Constructor.java:415) at

    android.view.LayoutInflater.createView(LayoutInflater.java:505) Caused

    by: java.lang.IllegalArgumentException: The handle attribute is

    required and must refer to a valid child. at

    com.example.androidapp.widgets.ExpandablePanel.(ExpandablePanel.java:39)

    解决方法:

    最后我发现了这个问题:

    在main.xml中查看以下行:

    xmlns:cl="http://schemas.android.com/apk/lib/com.example.androidapp.widgets"

    它应该是:

    xmlns:cl="http://schemas.android.com/apk/res/com.example.androidapp.widgets"

    因为我没有使用外部库和ExpandablePanel存在于res下.

    干杯.

    展开全文
  • LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding
  • android linearlayout错误,求大神

    千次阅读 2017-01-02 13:17:59
    android linearlayout错误,求大神 用手机执行软件,没图了  android:layout_width="fill_parent"  android:layout_height="fill_parent"  android:background="@drawable/timg"  android:orientation=...
  • LinearLayout在布局文件设置分割线不仅方便,而且高效,对于布局来说十分重要。然而我在为LinearLayout设置分割线的时候却碰到一个问题,十分不解。先来看看是什么现象吧:布局文件如下:<LinearLayout xmlns:...
  • import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.content.Context; import android.view.View; import android.widget.ImageView; ...
  • 我更新了我的android工作室,现在我的main.xml出现问题,它显示以下错误:必须声明元素LinearLayout这是我的代码:android:layout_height="fill_parent"android:layout_width="fill_parent"android:gravity="center_...
  • 我在stackoverflow上发现了自定义LinearLayout的这个例子,但是当我尝试运行它时会抛出错误,有人能找到它的错误吗?自定义LinearLayout:package com.example.androidapp.widgets;import android.content.Context;...
  • Android Studio常见布局报错及解决方案

    千次阅读 2019-06-17 02:10:46
    Set android:baselineAligned="false" on this ... 如果LinearLayout被用于嵌套的layout空间计算,它的android:baselineAligned属性应该设置成false,以加速layout计算 android:baselineAligned="false" This ...
  • 在Fragment下面使用LinearLayoutManager传入this和类名.this报错 解决方案: 传入this.getActivity(); RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view); LinearLayoutManager...
  • android开发最喜欢使用线性布局了,用着得心应手,爽歪歪,但是今天因为线性布局的坑,白忙活了...但是不行啊,只好用相对布局(RelativeLayout)作为根布局包裹线性布局咯(LinearLayout)。 修改后的代码如下: ...
  • 当想使用线性布局的嵌套,在一个LinearLayout里放了多个LinearLayout,却只显示一行 代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app=...
  • Error:Android Packager: [sport5] java.io.IOException: Cannot pack file E:\444\libs\production\sport5\sport5.unaligned.apk into itself 这几天一直在用Android studio 今天尝试了下把eclipse...
  • 运行了一个关于传感器的简单例子 ... 但程序一打开就自动关闭,提示unfortunately,***has stopped,在logcat里查看,显示 ...caused by java.lang.ClassNotFoundException android.view.linearlayout 于是上网搜索,在
  • Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. > java.io.IOException: Please correct the above warnings first.
  • as 报错

    2019-04-17 22:48:00
    cantnot find the declaration of element 'LinearLayout' 解决: 原本为了解决报错我把Android support关掉了,然后百度到解决办法是打开它,在setting-plugin 接着, 报错:Write access is allowed from ...
  • 1、引入布局方式// title.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="w
  • Android Studio RadioGroup

    2016-08-18 08:26:35
    ![图片说明](https://img-ask.csdn.net/upload/201608/18/1471508791_802755.png)
  • ConstrainLayout解决复杂的嵌套布局

    万次阅读 2017-03-03 10:26:04
    以前我们写布局,直接嵌套在LinearLayout或者RelativeLayout中,直接的约束条件就是layout_width和layout_height。但是,ConstrainLayout并不是这样子,他是通过你在布局界面 拖动控件,然后手动给他添加约束。因为...
  • 2、报错:android:baselineAligned="false"This LinearLayout layout or its RelativeLayout parent is useless多余的Linearlayout或者RelativeLayout删除即可;3、报错:This tag and its children can be replaced...
  • 发现Plugins下面都是红色的 ,比如Android Support (用红色矩形标注的),我报错时点进去查看的时候这个插件就是报红的,然后点击后面的对勾√再重新打上的时候Android Studio就提示你重启,点击弹出的提示框中的...
  • 错误:代码修改LinearLayout宽度时,报错java.lang.ClassCastException: android.widget.LinearLayoutLayoutParamscannotbecasttoandroid.widget.RelativeLayoutLayoutParams cannot be cast to android.widget....
  • 简单的两个LinearLayou嵌套就报错,在其他同学机上操作没有出现这样的问题,不论是按键拉出来的布局还是手动敲出来的代码都是有报错情况代码如下 <?xmlversion="1.0"encoding="UTF-8"?> <...
  • 报错:Multiple annotations found at this line: - Unexpected text found in layout file: "/>" - The element type "LinearLayout" must be terminated by the  matching end-tag "". 改正:将Linearlayout...
  • 问题原因:xrecyclerrview默认添加的header和footer,这就导致item的真实位置发生了变化, 解决方案:将item的位置由holder.getLayoutPosition()改为position 2.notifySetDataCahnged()无法刷新数据 ...
  • 在向另外一个Activity中的LinearLayout动态添加布局的时候,程序运行到addView会闪退,并且无法添加布局 public void new_tv(String message){ LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams...
  • android经常性错误解决

    2017-05-11 14:45:35
    RecyclerView: No layout manager attached; skipping layout

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 11,599
精华内容 4,639
关键字:

linearlayout报错