EditText使应用程序崩溃

时间:2013-07-22 09:53:35

标签: android android-edittext

这是我的登录布局的XML文件,现在我只编写了我的应用程序的布局部分,没有java编码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_background"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".LoginActivity" >

<TextView
    android:id="@+id/login_heading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/tv_login_heading"
    android:textColor="#000"
    android:textSize="20sp"
    android:textStyle="bold" />

<EditText
    android:id="@+id/et_uname"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="60dp"
    android:hint="@string/et_uname_hint"
    android:inputType="textEmailAddress"
    android:textColor="@string/tx_color" >


</EditText>

<EditText
    android:id="@+id/et_pwd"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:ems="10"
    android:hint="@string/et_pwd_hint"
    android:inputType="textPassword"
    android:textColor="@string/tx_color" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp" >

    <TextView
        android:id="@+id/tv_register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/register"
        android:textColor="@string/tx_color" />

    <TextView
        android:id="@+id/tv_settings"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/settings"
        android:textColor="@string/tx_color" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30dp" >

    <Button
        android:id="@+id/btn_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/btn_login"
        android:textColor="@string/tx_color" />

    <Button
        android:id="@+id/btn_exit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/btn_exit"
        android:textColor="@string/tx_color" />

</LinearLayout>

当我通过我的手机micromax canvas a110

运行时,它会在log cat中产生以下错误
07-22 15:02:34.210: E/AndroidRuntime(26110): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.blogspot.pcnlap.sha_login_activity_2/in.blogspot.pcnlap.sha_login_activity_2.LoginActivity}: android.view.InflateException: Binary XML file line #24: Error inflating class android.widget.EditText

我认为它是由于第24行的编辑文本而产生的。任何人都有想法解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我下载了你的项目并在我的系统上运行。 正如你所说,它导致EditText崩溃 我将android:textColor="@string/title_color"替换为android:textColor="@color/title_color 为此,您需要在values文件夹下创建color.xml文件,并将title_color值放在此color.xml文件中。 这解决了问题,我可以顺利运行您的项目。 希望你能得到这个。 问你是否还有疑问..

相关问题