在我的应用程序中,我已经格式化了我的xml文件,现在我将材料设计放在我的应用程序中,所以当我运行应用程序时,有一个问题来了,就像这些我正在运行的应用程序: - 在
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Binary XML file line #49: You must supply a layout_height attribute.
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:491)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5615)
at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:5756)
at android.widget.LinearLayout$LayoutParams.<init>(LinearLayout.java:1823)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1735)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:58)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:748)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.technotwit.newspaperwala.LoginDecision.WhoLogin.onCreate(WhoLogin.java:18)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
我的布局代码是: -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
tools:context=".WhoLogin">
<include layout="@layout/toolbar"/>
<LinearLayout
android:id="@+id/rootview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal">>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:paddingTop="20dp"
android:background="@drawable/circle"
android:drawableTop="@mipmap/userprofileimg"
android:text="Teacher Login"
android:textColor="#fff"
android:layout_gravity="center_horizontal"
android:id="@+id/Teacher" />
<android.support.v4.widget.Space
android:layout_width="20dp"
android:layout_height="2dp"
/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:paddingTop="20dp"
android:background="@drawable/circle"
android:drawableTop="@mipmap/userprofileimg"
android:text="Coordinator Login"
android:textColor="#fff"
android:layout_gravity="center_horizontal"
android:id="@+id/Coordinator" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Please Choose Your Login Domain"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:textColor="#030405"
android:textSize="20dp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
我的活动代码是: -
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.technotwit.newspaperwala.R;
public class WhoLogin extends AppCompatActivity {
Button teacherlogin,cordinatorlogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wlogin);
teacherlogin= (Button) findViewById(R.id.Teacher);
cordinatorlogin= (Button) findViewById(R.id.Coordinator);
teacherlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("who","teacher");
startActivity(i);
}
});
cordinatorlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i =new Intent(getApplicationContext(), MainActivity.class);
i.putExtra("who","coordinator");
startActivity(i);
}
});
}
}
在这一点上,我在坚持。
答案 0 :(得分:0)
引起:java.lang.RuntimeException:二进制XML文件行#49:您必须提供layout_height属性。
这是你的错误。如果单击其中一个按钮时发生这种情况,则错误发生在MainActivty布局文件中(activity_main.xml第49行)。将height属性添加到缺少它的元素。
答案 1 :(得分:0)
试试这段代码 toolbar.xml:
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:id="@+id/titletool"
android:textStyle="bold"/>
</android.support.v7.widget.Toolbar>
您的布局代码是:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
>
<include layout="@layout/toolbar"/>
<LinearLayout
android:id="@+id/rootview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal">>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:paddingTop="20dp"
android:background="@drawable/ic_launcher"
android:text="Teacher Login"
android:textColor="#fff"
android:layout_gravity="center_horizontal"
android:id="@+id/Teacher" />
<android.support.v4.widget.Space
android:layout_width="20dp"
android:layout_height="2dp"
/>
<Button
android:layout_width="150dp"
android:layout_height="150dp"
android:paddingTop="20dp"
android:background="@drawable/ic_launcher"
android:text="Coordinator Login"
android:textColor="#fff"
android:layout_gravity="center_horizontal"
android:id="@+id/Coordinator" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Please Choose Your Login Domain"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:textColor="#030405"
android:textSize="20dp" />
</RelativeLayout>
</LinearLayout>
它运行完美。这个
答案 2 :(得分:0)
感谢您的支持,但我通过使用和检查我的xml布局解决了这个问题 然后我编辑了我的代码,最后代码已经成功完成了