Android studio屡次停止运行

是这样的,博主想做一个登陆页面,再输入用户名和密码的时候会弹出登陆成功字样。然而页面可以正常打开
在这里插入图片描述
但输入之后单击登陆按钮就会闪退在这里插入图片描述
百度找了好多方法也没有解决,求助大神🙏
源码:login.java

package activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import net.hnjdzy.tinyaccount.R;

public class LoginActivity extends AppCompatActivity {
    Button btnLogin;
    EditText editTextName,editTextPwd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        btnLogin=(Button) this.findViewById(R.id.buttonLogin);//绑定按钮登录框
        editTextName=(EditText) this.findViewById(R.id.editTextName);//绑定用户名登录框
        editTextPwd=(EditText) this.findViewById(R.id.editTextTextPassword);//初始化控件

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Login();

            }
        });

}
//定义登录方法
    private void Login(){
       String name=editTextName.getText().toString(); //获取文本框输入的姓名
         String pwd=editTextPwd.getText().toString();//获取文本框输入的密码
        if(name.equals("admin")&&pwd.equals("admin")){
            Toast.makeText(this,"登录成功",Toast.LENGTH_LONG).show();//弹出登录成功窗口,要用到Toast类的makeText方法
            //三个信息,第一个上下文,第二个提示的信息,第三个提示显示的时间
        }

        else{
            Toast.makeText(this,"登录失败",Toast.LENGTH_LONG).show();//弹出登录失败窗口
        }
    }
    }

login.xml:

<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical"
    tools:context="activity.LoginActivity">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimary"
            app:srcCompat="@drawable/default_user_logo" />


    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        tools:ignore="ExtraText"
        android:layout_marginTop="50dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        >

        <TextView
            android:id="@+id/textView11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="用户昵称" />

        <EditText
            android:id="@+id/editTextName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
             android:hint="请输入用户名" />

        <TextView
            android:id="@+id/textView13"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="密码" />

        <EditText
            android:id="@+id/editTextPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPassword"
            android:hint="请输入密码"/>

        <Button
            android:id="@+id^ttonLogin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FF8833"
            android:text="登录" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_marginTop="20dp"
        >

        <TextView
            android:id="@+id/textViewNoPassword"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/colorPrimary"
            android:layout_weight="1"
            android:layout_marginLeft="10dp"

            android:text="忘记密码" />

        <TextView
            android:id="@+id/textViewRegister"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/colorPrimary"
            android:layout_weight="1"
            android:gravity="right"
            android:layout_marginRight="10dp"
            android:text="注册用户" />
    </LinearLayout>


</LinearLayout>

谢谢

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值