膨胀异常 - 错误膨胀textview

时间:2016-05-31 09:22:20

标签: android xml validation

我有这项主要活动。我在Login按钮上调用了validate方法。但是,当我点击按钮时,我没有收到错误消息,我的应用程序崩溃了。任何帮助,将不胜感激。谢谢。 这是我的MainActivity Java类

ifstream file("input.txt");
string   line;

while(!file.eof())
{
    string name;
    string surname;
    string years;

    file >> name >> surname >> years;

    cout<<name<<" "<<surname<<" "<<years<<endl;
}

这是我的xml文件

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

public Button blogin;
public TextView signup;
public EditText uname, pass;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    uname = (EditText) findViewById(R.id.uname);
    pass = (EditText) findViewById(R.id.pass);
    signup = (TextView) findViewById(R.id.signup);
    blogin = (Button) findViewById(R.id.blogin);

    blogin.setOnClickListener(this);
    signup.setOnClickListener(this);


}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.blogin:


            validate();




            break;

        case R.id.signup:
            startActivity(new Intent(this, SignUp.class));
            break;
    }
}

@Override
protected void onPause() {
    super.onPause();
}

public boolean validate() {
    boolean valid = true;

    String email = uname.getText().toString();
    String password = pass.getText().toString();

    if (email.isEmpty() || !Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        uname.setError("Enter a valid email address");


        valid = false;
    } else {
        uname.setError(null);
    }

    if (password.isEmpty() || password.length() < 4 || password.length() > 10) {
        pass.setError("Enter a password between 4 and 10 alphanumeric characters");


     valid = false;
    } else {
        pass.setError(null);
    }

    return valid;
}
}

样式文件

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:fillViewport="true">


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_above="@+id/uname"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/logo" />

    <!--<requestFocus />-->

    <EditText
        android:id="@+id/uname"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/pass"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:drawableLeft="@drawable/ic_perm_identity_black_24dp"
        android:drawablePadding="10dp"
        android:hint="Username"
        android:inputType="textEmailAddress"
        android:paddingLeft="10dp"
        android:textColor="#000000"
        android:theme="@style/TextLabel" />

    <EditText
        android:id="@+id/pass"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:drawableLeft="@drawable/ic_lock_outline_black_24dp"
        android:drawablePadding="10dp"
        android:hint="Password"
        android:inputType="textPassword"
        android:paddingLeft="10dp"
        android:theme="@style/TextLabel" />

    <android.support.v7.widget.AppCompatButton
        android:id="@+id/blogin"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_below="@+id/pass"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:layout_marginTop="35dp"
        android:background="@drawable/shape"
        android:fontFamily="sans-serif"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:text="Login"
        android:textAlignment="center"
        android:textColor="#ffffff"
        android:textSize="15dp" />
    <!--style="?android:attr/borderlessButtonStyle"-->


    <TextView
        android:id="@+id/forgot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/blogin"
        android:layout_marginTop="30dp"
        android:layout_toLeftOf="@+id/textView3"
        android:layout_toStartOf="@+id/textView3"
        android:gravity="center"
        android:paddingRight="5dp"
        android:text="Forgot Password?"
        android:textColor="#000000"
        android:textSize="15dp"
        android:textStyle="normal" />

    <TextView
        android:id="@+id/signup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView3"
        android:layout_toEndOf="@+id/textView3"
        android:layout_toRightOf="@+id/textView3"
        android:gravity="center"
        android:paddingLeft="5dp"
        android:text="New user? Sign up"
        android:textColor="#000000"
        android:textSize="15dp"
        android:textStyle="normal" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/forgot"
        android:layout_centerHorizontal="true"
        android:text="|"
        android:textColor="#000000"
        android:textSize="15dp" />


</RelativeLayout>
</ScrollView>

我收到错误 -                                                                              android.view.InflateException:二进制XML文件行#17:二进制XML文件行#17:错误膨胀类TextView

1 个答案:

答案 0 :(得分:6)

问题在于TextLabel样式的父主题。我将其更改为parent =&#34; AppTheme.NoActionBar。现在它正常工作。