Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 充气异常-充气文本视图时出错_Android_Xml_Validation - Fatal编程技术网

Android 充气异常-充气文本视图时出错

Android 充气异常-充气文本视图时出错,android,xml,validation,Android,Xml,Validation,我有这个主要的活动。我已经调用了登录按钮上的验证方法。但是,当我点击按钮时,我没有得到错误消息,我的应用程序崩溃了。任何帮助都将不胜感激。非常感谢。 这是我的MainActivity Java类 public class MainActivity extends AppCompatActivity implements View.OnClickListener { public Button blogin; public TextView signup; public EditText una

我有这个主要的活动。我已经调用了登录按钮上的验证方法。但是,当我点击按钮时,我没有得到错误消息,我的应用程序崩溃了。任何帮助都将不胜感激。非常感谢。 这是我的MainActivity Java类

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;
}
}
public类MainActivity扩展AppCompatActivity实现View.OnClickListener{
公共按钮博客;
公共文本视图注册;
公共编辑文本uname,pass;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uname=(EditText)findViewById(R.id.uname);
pass=(EditText)findViewById(R.id.pass);
注册=(TextView)findViewById(R.id.signup);
blogin=(按钮)findviewbyd(R.id.blogin);
setOnClickListener(this);
signup.setOnClickListener(this);
}
@凌驾
公共void onClick(视图v){
开关(v.getId()){
案例R.id.blogin:
验证();
打破
案例R.id.注册:
startActivity(新意图(这个,SignUp.class));
打破
}
}
@凌驾
受保护的void onPause(){
super.onPause();
}
公共布尔验证(){
布尔有效=真;
字符串email=uname.getText().toString();
字符串密码=pass.getText().toString();
if(email.isEmpty()| |!Patterns.email|u ADDRESS.matcher(email.matches()){
uname.setError(“输入有效的电子邮件地址”);
有效=错误;
}否则{
uname.setError(null);
}
if(password.isEmpty()| | password.length()<4 | | password.length()>10){
pass.setError(“输入介于4到10个字母数字字符之间的密码”);
有效=错误;
}否则{
pass.setError(null);
}
返回有效;
}
}
这是我的xml文件

<?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>

样式文件

    <style name="TextLabel" parent="TextAppearance.AppCompat">
    <item name="android:textColorHint">@color/HintColor</item>
    <item name="android:textSize">15sp</item>
    <item name="colorAccent">@color/editTextLine</item>
    <item name="colorControlNormal">@color/editTextLine</item>
    <item name="colorControlActivated">@color/editTextActivated</item>
    <item name="android:textColor">@color/textColor</item>
</style>

@颜色/铰链颜色
15便士
@颜色/编辑文本行
@颜色/编辑文本行
@颜色/编辑文本已激活
@颜色/文本颜色
我收到错误-
android.view.InflateException:二进制XML文件行#17:二进制XML文件行#17:膨胀类TextView时出错

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

我已经在没有android:theme=“@style/textlab”的情况下测试了您的xml,并且工作正常。即时运行可能有问题,请尝试重新生成project@Alexander谢谢。我试过了,是的,没有android:theme=“@style/TextLabel”也能用“。但为什么它不适合这个主题?@NamrataSingh分享你的风格xml@Kenumir不,不是。我照你说的做了,但问题仍然存在。这真的是修复我的崩溃。谢谢,我也是!谢谢分享!