I am getting error - Binary XML file line #14: Error inflating class

Eious

New Member
I am creating an application for android, at first i used one library project to include Panel functionality in the application and it worked fine. Later i found that my .apk file included my unused images and xml file of library project which increased the size of my application, so i decided to implement the panel functionality on my own. When i ran the application after making the changes i am getting the error. The log cat is as below\[code\]09-28 00:01:00.639: E/AndroidRuntime(1462): FATAL EXCEPTION: main09-28 00:01:00.639: E/AndroidRuntime(1462): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.widgets.application/com.widgets.application.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class com.widgets.application.utils.Panel09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.ActivityThread.access$1500(ActivityThread.java:117)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.os.Handler.dispatchMessage(Handler.java:99)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.os.Looper.loop(Looper.java:123)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.ActivityThread.main(ActivityThread.java:3683)09-28 00:01:00.639: E/AndroidRuntime(1462): at java.lang.reflect.Method.invokeNative(Native Method)09-28 00:01:00.639: E/AndroidRuntime(1462): at java.lang.reflect.Method.invoke(Method.java:507)09-28 00:01:00.639: E/AndroidRuntime(1462): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)09-28 00:01:00.639: E/AndroidRuntime(1462): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)09-28 00:01:00.639: E/AndroidRuntime(1462): at dalvik.system.NativeStart.main(Native Method)09-28 00:01:00.639: E/AndroidRuntime(1462): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class com.widgets.application.utils.Panel09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.createView(LayoutInflater.java:518)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)09-28 00:01:00.639: E/AndroidRuntime(1462): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.Activity.setContentView(Activity.java:1657)09-28 00:01:00.639: E/AndroidRuntime(1462): at com.widgets.application.MainActivity.onCreate(MainActivity.java:65)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)09-28 00:01:00.639: E/AndroidRuntime(1462): ... 11 more09-28 00:01:00.639: E/AndroidRuntime(1462): Caused by: java.lang.reflect.InvocationTargetException09-28 00:01:00.639: E/AndroidRuntime(1462): at java.lang.reflect.Constructor.constructNative(Native Method)09-28 00:01:00.639: E/AndroidRuntime(1462): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)09-28 00:01:00.639: E/AndroidRuntime(1462): at android.view.LayoutInflater.createView(LayoutInflater.java:505)09-28 00:01:00.639: E/AndroidRuntime(1462): ... 22 more09-28 00:01:00.639: E/AndroidRuntime(1462): Caused by: java.lang.IllegalArgumentException: Binary XML file line #14: The content attribute is required and must refer to a valid child.09-28 00:01:00.639: E/AndroidRuntime(1462): at com.widgets.application.utils.Panel.<init>(Panel.java:116)09-28 00:01:00.639: E/AndroidRuntime(1462): ... 25 more\[/code\]activity_main.xml\[code\]<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:panel="http://schemas.android.com/apk/com.widgets.application.utils.Panel"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#CCC"android:orientation="vertical" ><LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <com.widgets.application.utils.Panel android:id="@+id/mytopPanel" android:layout_width="fill_parent" android:layout_height="wrap_content" panel:animationDuration="1000" panel:closedHandle="@drawable/top_switcher_collapsed_background" panel:content="@+id/mypanelContent" panel:handle="@+id/mypanelHandle" panel:linearFlying="true" panel:openedHandle="@drawable/top_switcher_expanded_background" panel:position="top" > <Button android:id="@+id/mypanelHandle" android:layout_width="wrap_content" android:layout_height="33dip" android:layout_gravity="center_horizontal" /> <HorizontalScrollView android:id="@+id/mypanelContent" android:layout_width="fill_parent" android:layout_height="wrap_content" > <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#CCC" android:orientation="vertical" > <EditText android:id="@+id/editTextWay" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:layout_marginTop="6dp" android:maxLength="10" android:inputType="number" android:hint="@string/editUserName" /> <EditText android:id="@+id/editTextWay1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:hint="@string/editUserWay2Pwd" android:inputType="textPassword" /> <TextView android:id="@+id/textView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#323299" android:gravity="center" android:padding="4dip" android:text="@string/drpDwnTxtWay2sms" android:textColor="#eee" android:textSize="16dip" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@+id/linearLayout" android:orientation="vertical" > <EditText android:id="@+id/editTextFul" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:layout_marginTop="6dp" android:hint="@string/editUserName" android:maxLength="10" android:inputType="number" /> <EditText android:id="@+id/editTextFul1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:hint="@string/editUserFullPwd" android:inputType="textPassword" /> <TextView android:id="@+id/textView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#322399" android:gravity="center" android:padding="4dip" android:text="@string/drpDwnTxtFull" android:textColor="#eee" android:textSize="16dip" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@+id/linearLayout1" android:orientation="vertical" > <EditText android:id="@+id/editTextUl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:layout_marginTop="6dp" android:maxLength="10" android:inputType="number" android:hint="@string/editUserName" /> <EditText android:id="@+id/editTextUl1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:hint="@string/editUserUltooPwd" android:inputType="textPassword" /> <TextView android:id="@+id/textView2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#323299" android:gravity="center" android:padding="4dip" android:text="@string/drpDwnTxtUltoo" android:textColor="#eee" android:textSize="16dip" android:textStyle="bold" /> </LinearLayout> <LinearLayout android:id="@+id/linearLayout3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@+id/linearLayout2" android:orientation="vertical" > <EditText android:id="@+id/editTextBy" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:layout_marginTop="6dp" android:maxLength="10" android:inputType="number" android:hint="@string/editUserName" /> <EditText android:id="@+id/editTextBy1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="3dp" android:hint="@string/editUserByTwoPwd" android:inputType="textPassword" /> <TextView android:id="@+id/textView3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#322399" android:gravity="center" android:padding="4dip" android:text="@string/drpDwnTxtByTwo" android:textColor="#eee" android:textSize="16dip" android:textStyle="bold" /> </LinearLayout> </RelativeLayout> </HorizontalScrollView> </com.widgets.application.utils.Panel> </LinearLayout></FrameLayout>\[/code\]Panel.java\[code\]public class Panel extends LinearLayout {private static final String TAG = "Panel";public static interface OnPanelListener { public void onPanelClosed(Panel panel); public void onPanelOpened(Panel panel);}private boolean mIsShrinking;private int mPosition;private int mDuration;private boolean mLinearFlying;private int mHandleId;private int mContentId;private View mHandle;private View mContent;private Drawable mOpenedHandle;private Drawable mClosedHandle;private float mTrackX;private float mTrackY;private float mVelocity;private OnPanelListener panelListener;public static final int TOP = 0;public static final int BOTTOM = 1;public static final int LEFT = 2;public static final int RIGHT = 3;private enum State { ABOUT_TO_ANIMATE, ANIMATING, READY, TRACKING, FLYING,};private State mState;private Interpolator mInterpolator;private GestureDetector mGestureDetector;private int mContentHeight;private int mContentWidth;private int mOrientation;private float mWeight;private PanelOnGestureListener mGestureListener;private boolean mBringToFront;public Panel(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Panel); mDuration = a.getInteger(R.styleable.Panel_animationDuration, 750); mPosition = a.getInteger(R.styleable.Panel_position, BOTTOM); mLinearFlying = a.getBoolean(R.styleable.Panel_linearFlying, false); mWeight = a.getFraction(R.styleable.Panel_weight, 0, 1, 0.0f); if (mWeight < 0 || mWeight > 1) { mWeight = 0.0f; Log.w(TAG, a.getPositionDescription() + ": weight must be > 0 and <= 1"); } mOpenedHandle = a.getDrawable(R.styleable.Panel_openedHandle); mClosedHandle = a.getDrawable(R.styleable.Panel_closedHandle); RuntimeException e = null; mHandleId = a.getResourceId(R.styleable.Panel_handle, 0); if (mHandleId == 0) { e = new IllegalArgumentException( a.getPositionDescription() + ": The handle attribute is required and must refer to a valid child."); } mContentId = a.getResourceId(R.styleable.Panel_content, 0); if (mContentId == 0) { e = new IllegalArgumentException( a.getPositionDescription() + ": The content attribute is required and must refer to a valid child."); } a.recycle(); if (e != null) { throw e; } mOrientation = (mPosition == TOP || mPosition == BOTTOM) ? VERTICAL : HORIZONTAL; setOrientation(mOrientation); mState = State.READY; mGestureListener = new PanelOnGestureListener(); mGestureDetector = new GestureDetector(mGestureListener); mGestureDetector.setIsLongpressEnabled(false); setBaselineAligned(false);}public void setOnPanelListener(OnPanelListener onPanelListener) { panelListener = onPanelListener;}public View getHandle() { return mHandle;}public View getContent() { return mContent;}public void setInterpolator(Interpolator i) { mInterpolator = i;}public boolean setOpen(boolean open, boolean animate) { if (mState == State.READY && isOpen() ^ open) { mIsShrinking = !open; if (animate) { mState = State.ABOUT_TO_ANIMATE; if (!mIsShrinking) { mContent.setVisibility(VISIBLE); } post(startAnimation); } else { mContent.setVisibility(open ? VISIBLE : GONE); postProcess(); } return true; } return false;}public boolean isOpen() { return mContent.getVisibility() == VISIBLE;}@Overrideprotected void onFinishInflate() { super.onFinishInflate(); mHandle = findViewById(mHandleId); if (mHandle == null) { String name = getResources().getResourceEntryName(mHandleId); throw new RuntimeException( "Your Panel must have a child View whose id attribute is 'R.id." + name + "'"); } mHandle.setOnTouchListener(touchListener); mHandle.setOnClickListener(clickListener); mContent = findViewById(mContentId); if (mContent == null) { String name = getResources().getResourceEntryName(mHandleId); throw new RuntimeException( "Your Panel must have a child View whose id attribute is 'R.id." + name + "'"); } removeView(mHandle); removeView(mContent); if (mPosition == TOP || mPosition == LEFT) { addView(mContent); addView(mHandle); } else { addView(mHandle); addView(mContent); } if (mClosedHandle != null) { mHandle.setBackgroundDrawable(mClosedHandle); } mContent.setClickable(true); mContent.setVisibility(GONE); if (mWeight > 0) { ViewGroup.LayoutParams params = mContent.getLayoutParams(); if (mOrientation == VERTICAL) { params.height = ViewGroup.LayoutParams.FILL_PARENT; } else { params.width = ViewGroup.LayoutParams.FILL_PARENT; } mContent.setLayoutParams(params); }}@Overrideprotected void onAttachedToWindow() { super.onAttachedToWindow(); ViewParent parent = getParent(); if (parent != null && parent instanceof FrameLayout) { mBringToFront = true; }}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (mWeight > 0 && mContent.getVisibility() == VISIBLE) { View parent = (View) getParent(); if (parent != null) { if (mOrientation == VERTICAL) { heightMeasureSpec = MeasureSpec.makeMeasureSpec( (int) (parent.getHeight() * mWeight), MeasureSpec.EXACTLY); } else { widthMeasureSpec = MeasureSpec.makeMeasureSpec( (int) (parent.getWidth() * mWeight), MeasureSpec.EXACTLY); } } } super.onMeasure(widthMeasureSpec, heightMeasureSpec);}@Overrideprotected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); mContentWidth = mContent.getWidth(); mContentHeight = mContent.getHeight();}@Overrideprotected void dispatchDraw(Canvas canvas) { if (mState == State.ABOUT_TO_ANIMATE && !mIsShrinking) { int delta = mOrientation == VERTICAL ? mContentHeight : mContentWidth; if (mPosition == LEFT || mPosition == TOP) { delta = -delta; } if (mOrientation == VERTICAL) { canvas.translate(0, delta); } else { canvas.translate(delta, 0); } } if (mState == State.TRACKING || mState == State.FLYING) { canvas.translate(mTrackX, mTrackY); } super.dispatchDraw(canvas);}private float ensureRange(float v, int min, int max) { v = Math.max(v, min); v = Math.min(v, max); return v;}OnTouchListener touchListener = new OnTouchListener() { int initX; int initY; boolean setInitialPosition; public boolean onTouch(View v, MotionEvent event) { if (mState == State.ANIMATING) { return false; } int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN) { if (mBringToFront) { bringToFront(); } initX = 0; initY = 0; if (mContent.getVisibility() == GONE) { if (mOrientation == VERTICAL) { initY = mPosition == TOP ? -1 : 1; } else { initX = mPosition == LEFT ? -1 : 1; } } setInitialPosition = true; } else { if (setInitialPosition) { initX *= mContentWidth; initY *= mContentHeight; mGestureListener.setScroll(initX, initY); setInitialPosition = false; initX = -initX; initY = -initY; } event.offsetLocation(initX, initY); } if (!mGestureDetector.onTouchEvent(event)) { if (action == MotionEvent.ACTION_UP) { post(startAnimation); } } return false; }};OnClickListener clickListener = new OnClickListener() { public void onClick(View v) { if (mBringToFront) { bringToFront(); } if (initChange()) { post(startAnimation); } }};public boolean initChange() { if (mState != State.READY) { return false; } mState = State.ABOUT_TO_ANIMATE; mIsShrinking = mContent.getVisibility() == VISIBLE; if (!mIsShrinking) { mContent.setVisibility(VISIBLE); } return true;}Runnable startAnimation = new Runnable() { public void run() { TranslateAnimation animation; int fromXDelta = 0, toXDelta = 0, fromYDelta = 0, toYDelta = 0; if (mState == State.FLYING) { mIsShrinking = (mPosition == TOP || mPosition == LEFT) ^ (mVelocity > 0); } int calculatedDuration; if (mOrientation == VERTICAL) { int height = mContentHeight; if (!mIsShrinking) { fromYDelta = mPosition == TOP ? -height : height; } else { toYDelta = mPosition == TOP ? -height : height; } if (mState == State.TRACKING) { if (Math.abs(mTrackY - fromYDelta) < Math.abs(mTrackY - toYDelta)) { mIsShrinking = !mIsShrinking; toYDelta = fromYDelta; } fromYDelta = (int) mTrackY; } else if (mState == State.FLYING) { fromYDelta = (int) mTrackY; } if (mState == State.FLYING && mLinearFlying) { calculatedDuration = (int) (1000 * Math .abs((toYDelta - fromYDelta) / mVelocity)); calculatedDuration = Math.max(calculatedDuration, 20); } else { calculatedDuration = mDuration * Math.abs(toYDelta - fromYDelta) / mContentHeight; } } else { int width = mContentWidth; if (!mIsShrinking) { fromXDelta = mPosition == LEFT ? -width : width; } else { toXDelta = mPosition == LEFT ? -width : width; } if (mState == State.TRACKING) { if (Math.abs(mTrackX - fromXDelta) < Math.abs(mTrackX - toXDelta)) { mIsShrinking = !mIsShrinking; toXDelta = fromXDelta; } fromXDelta = (int) mTrackX; } else if (mState == State.FLYING) { fromXDelta = (int) mTrackX; } if (mState == State.FLYING && mLinearFlying) { calculatedDuration = (int) (1000 * Math .abs((toXDelta - fromXDelta) / mVelocity)); calculatedDuration = Math.max(calculatedDuration, 20); } else { calculatedDuration = mDuration * Math.abs(toXDelta - fromXDelta) / mContentWidth; } } mTrackX = mTrackY = 0; if (calculatedDuration == 0) { mState = State.READY; if (mIsShrinking) { mContent.setVisibility(GONE); } postProcess(); return; } animation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta); animation.setDuration(calculatedDuration); animation.setAnimationListener(animationListener); if (mState == State.FLYING && mLinearFlying) { animation.setInterpolator(new LinearInterpolator()); } else if (mInterpolator != null) { animation.setInterpolator(mInterpolator); } startAnimation(animation); }};private AnimationListener animationListener = new AnimationListener() { public void onAnimationEnd(Animation animation) { mState = State.READY; if (mIsShrinking) { mContent.setVisibility(GONE); } postProcess(); } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { mState = State.ANIMATING; }};private void postProcess() { if (mIsShrinking && mClosedHandle != null) { mHandle.setBackgroundDrawable(mClosedHandle); } else if (!mIsShrinking && mOpenedHandle != null) { mHandle.setBackgroundDrawable(mOpenedHandle); } if (panelListener != null) { if (mIsShrinking) { panelListener.onPanelClosed(Panel.this); } else { panelListener.onPanelOpened(Panel.this); } }}class PanelOnGestureListener implements OnGestureListener { float scrollY; float scrollX; public void setScroll(int initScrollX, int initScrollY) { scrollX = initScrollX; scrollY = initScrollY; } public boolean onDown(MotionEvent e) { scrollX = scrollY = 0; initChange(); return true; } public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { mState = State.FLYING; mVelocity = mOrientation == VERTICAL ? velocityY : velocityX; post(startAnimation); return true; } public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { mState = State.TRACKING; float tmpY = 0, tmpX = 0; if (mOrientation == VERTICAL) { scrollY -= distanceY; if (mPosition == TOP) { tmpY = ensureRange(scrollY, -mContentHeight, 0); } else { tmpY = ensureRange(scrollY, 0, mContentHeight); } } else { scrollX -= distanceX; if (mPosition == LEFT) { tmpX = ensureRange(scrollX, -mContentWidth, 0); } else { tmpX = ensureRange(scrollX, 0, mContentWidth); } } if (tmpX != mTrackX || tmpY != mTrackY) { mTrackX = tmpX; mTrackY = tmpY; invalidate(); } return true; }}}\[/code\]MainActivity.java\[code\]import com.widgets.application.utils.Panel;import com.widgets.application.utils.Panel.OnPanelListener; public class MainActivity extends Activity implements OnPanelListener, OnClickListener, OnItemClickListener {final static int RQS_PICK_CONTACT = 1;Context context;@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main);}public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {}public void onClick(View arg0) {}public void onPanelClosed(Panel panel) {}public void onPanelOpened(Panel panel) {}}\[/code\]attrs.xml\[code\]<?xml version="1.0" encoding="utf-8"?><resources><declare-styleable name="Panel"> <attr name="animationDuration" format="integer" /> <attr name="position"> <enum name="top" value="http://stackoverflow.com/questions/12658313/0" /> <enum name="bottom" value="http://stackoverflow.com/questions/12658313/1" /> <enum name="left" value="http://stackoverflow.com/questions/12658313/2" /> <enum name="right" value="http://stackoverflow.com/questions/12658313/3" /> </attr> <attr name="handle" format="reference" /> <attr name="content" format="reference" /> <attr name="linearFlying" format="boolean" /> <attr name="weight" format="fraction" /> <attr name="openedHandle" format="reference|color" /> <attr name="closedHandle" format="reference|color" /></declare-styleable><declare-styleable name="SmoothButton"> <attr name="transitionDrawable" format="reference" /> <attr name="transitionDrawableLength" format="integer" /> <attr name="transitionTextColorUp" format="color" /> <attr name="transitionTextColorDown" format="color" /></declare-styleable><declare-styleable name="Switcher"> <attr name="animationDuration" /> <attr name="idleTimeout" format="integer" /> <attr name="decreaseButton" format="reference" /> <attr name="increaseButton" format="reference" /></declare-styleable></resources>\[/code\]
 
Back
Top