When I run my application I got the following errors:
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: FATAL EXCEPTION: main
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: Process: com.siddhu.user.shapes, PID: 13878
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.siddhu.user.shapes/com.siddhu.user.shapes.Shapes_2d}: java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_width attribute.
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: Caused by: java.lang.RuntimeException: Binary XML file line #21: You must supply a layout_width attribute.
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:606)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:6472)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6641)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1864)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1776)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:62)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:808)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.Activity.setContentView(Activity.java:2145)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at com.siddhu.user.shapes.Shapes_2d.onCreate(Shapes_2d.java:22)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:151)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5254)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
11-04 15:47:11.808 13878-13878/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
I check my xml and java class i did not find any mistake. I think I am doing no mistake in xml file and can any one solve this issue? I registered the all the classes in android manifest file. I don't know where the error was raising.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
android:background="@drawable/subpage01_bg"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="2D Shapes"
android:textSize="72dp"
android:id="@+id/textView"
android:textStyle="bold"
android:layout_gravity="center_horizontal" />
<ImageView
android:layout_width="@dimen/subpage_ele_width"
android:layout_height="@dimen/subpage_ele_height"
android:id="@+id/subpg1_ele"
android:src="@drawable/subpage01_3d_ele"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="@dimen/shapes3d_linearlayout_width"
android:orientation="vertical"
android:weightSum="2"
android:layout_height="@dimen/shapes3d_linearlayout_height">
<ImageView
android:layout_width="@dimen/shapes3d_cube_width"
android:layout_height="@dimen/shapes3d_cube_height"
android:src="@drawable/subpage01_circle"
android:stateListAnimator="@anim/raise"
android:id="@+id/cicle"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="@dimen/shapes3d_text_width"
android:layout_height="@dimen/shapes3d_text_height"
android:layout_gravity="center_horizontal|center_vertical"
android:textStyle="bold"
android:text=" Circle"
android:textSize="35dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="@dimen/shapes3d_linearlayout_width"
android:orientation="vertical"
android:weightSum="2"
android:layout_height="@dimen/shapes3d_linearlayout_height">
<ImageView
android:layout_width="@dimen/shapes3d_cube_width"
android:layout_height="@dimen/shapes3d_cube_height"
android:src="@drawable/subpage01_square"
android:stateListAnimator="@anim/raise"
android:id="@+id/rectangle"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="@dimen/shapes3d_text_width"
android:layout_height="@dimen/shapes3d_text_height"
android:layout_gravity="center_horizontal|center_vertical"
android:textStyle="bold"
android:text="Rectangle"
android:textSize="30dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="@dimen/shapes3d_linearlayout_width"
android:orientation="vertical"
android:weightSum="2"
android:layout_height="@dimen/shapes3d_linearlayout_height">
<ImageView
android:layout_width="@dimen/shapes3d_cube_width"
android:layout_height="@dimen/shapes3d_cube_height"
android:stateListAnimator="@anim/raise"
android:src="@drawable/subpage01_triangle"
android:id="@+id/triangle"
android:scaleType="fitXY"
android:layout_gravity="center_horizontal" />
<TextView
android:layout_width="@dimen/shapes3d_text_width"
android:layout_height="@dimen/shapes3d_text_height"
android:layout_gravity="center_horizontal|center_vertical"
android:textStyle="bold"
android:text="Triangle"
android:textSize="35dp"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
以下是我的dimens.xml可以解决和解释问题。未来 引用。我认为我正确地定义了有关布局和文本视图以及所有其他视图的所有属性。有人说你的布局中删除了重量总和。它是否导致崩溃我不知道.plz任何人帮我解决问题。
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">64dp</dimen>
<dimen name="activity_vertical_margin">72dp</dimen>
<dimen name="mainpg_imgbtn_text">30dp</dimen>
<dimen name="mainpg_text_width">360dp</dimen>
<dimen name="mainpg_text_height">120dp</dimen>
<dimen name="mainpage_imgbtn_height">150dp</dimen>
<dimen name="mainpage_imgbtn_width">150dp</dimen>
<dimen name="mainpage_linearlayout_height">200dp</dimen>
<dimen name="mainpage_animation_image_height">120dp</dimen>
<dimen name="mainpage_animation_image_width">120dp</dimen>
<dimen name="mainpage_imgbtn_text_height">50dp</dimen>
<dimen name="mainpage_imgbtn_text_width">150dp</dimen>
<dimen name="mainpg_headtext_size">96dp</dimen>
<dimen name="mainpg_bird_width">250dp</dimen>
<dimen name="mainpg_bird_height">250dp</dimen>
<dimen name="subpage_ele_width">200dp</dimen>
<dimen name="subpage_ele_height">200dp</dimen>
<dimen name="shapes3d_cube_width">150dp</dimen>
<dimen name="shapes3d_cube_height">150dp</dimen>
<dimen name="shapes3d_rab_height">250dp</dimen>
<dimen name="shapes3d_rab_width">250dp</dimen>
<dimen name="shapes3d_rab_marginleft">100dp</dimen>
<dimen name="shapes3d_text_width">150dp</dimen>
<dimen name="shapes3d_text_height">50dp</dimen>
<dimen name="shapes3d_home_margintop">10dp</dimen>
<dimen name="shapes3d_linearlayout_height">200dp</dimen>
<dimen name="shapes3d_linearlayout_width">200dp</dimen>
<dimen name="circles_around_text_height">100dp</dimen>
<dimen name="circles_around_text_width">320dp</dimen>
<dimen name="circles_around_text_size">64dp</dimen>
<dimen name="circles_around_linearlayout_width">600dp</dimen>
<dimen name="circles_around_linearlayout_height">150dp</dimen>
<dimen name="circles_around_image_width">150dp</dimen>
<dimen name="circles_around_image_height">150dp</dimen>
<dimen name="drag_and_drop_image_width">100dp</dimen>
<dimen name="drag_and_drop_image_height">100dp</dimen>
<dimen name="oddone_image_width">64dp</dimen>
<dimen name="oddone_image_height">64dp</dimen>
<dimen name="games_image_width">64dp</dimen>
<dimen name="games_image_height">64dp</dimen>
<dimen name="games_linearlayout_width">300dp</dimen>
<dimen name="games_linearlayout_height">300dp</dimen>
<dimen name="games_marginleft">-72dp</dimen>
<dimen name="tap_image_width">100dp</dimen>
<dimen name="tap_image_height">80dp</dimen>
<dimen name="tap_linearlayout_width">600dp</dimen>
<dimen name="tap_linearlayout_height">100dp</dimen>
<dimen name="subpage2_linearlayout_height">250dp</dimen>
<dimen name="sp2menu">75dp</dimen>
<dimen name="sp2back">75dp</dimen>
<dimen name="sp2home">75dp</dimen>
<dimen name="sp4_imageview_height">200dp</dimen>
<dimen name="sp4_imageview_width">200dp</dimen>
</resources>
答案 0 :(得分:0)
<LinearLayout
android:layout_width="@dimen/shapes3d_linearlayout_width"
android:orientation="vertical"
android:weightSum="2"
android:layout_height="@dimen/shapes3d_linearlayout_height">
在所有布局设置宽度和高度作为包裹/匹配/填充watever你想要但不在维度
答案 1 :(得分:-1)
删除所有weightSum,你没有使用它们,然后检查所有@dimen值是否存在且没问题。