我是android开发的新手。我正在尝试制作一个简单的登录和注册表格。我有一个TextView'Sign up',基本上在单击时会将用户带到registerActivity,但是每次我单击注册TextView时,它都会使我的应用程序崩溃。我已经搜索了解决方案,但似乎无法找出导致崩溃的原因。
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"
tools:context=".LoginActivity"
android:orientation="vertical"
android:gravity="center_horizontal"
android:background="@drawable/bg"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_marginTop="70dp"
app:srcCompat="@drawable/logo"
/>
<EditText
android:id="@+id/edittext_username"
android:layout_width="249dp"
android:layout_height="71dp"
android:layout_marginTop="20dp"
android:drawableLeft="@drawable/user"
android:drawablePadding="10dp"
android:textColorHint="#f8f8f8"
android:paddingLeft="15dp"
android:hint="@string/mobile"
android:textColor="#f8f8f8"
android:background="@drawable/rounded_edittext" />
<EditText
android:id="@+id/edittext_password"
android:layout_width="249dp"
android:layout_height="71dp"
android:layout_marginTop="20dp"
android:drawableLeft="@drawable/password"
android:drawablePadding="10dp"
android:textColorHint="#f8f8f8"
android:paddingLeft="15dp"
android:hint="@string/password"
android:textColor="#f8f8f8"
android:background="@drawable/rounded_edittext"/>
<Button
android:id="@+id/button_login"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:background="@drawable/rounded_buttons"
android:text="@string/login"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Not Registered?"
android:textColor="#000000" />
<TextView
android:id="@+id/textview_register"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:paddingLeft="5dp"
android:textStyle="bold"
android:textColor="#e8170c"
android:text="@string/register"/>
</LinearLayout>
JAVA:
package com.example.careerhunts.raw;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class LoginActivity extends AppCompatActivity {
EditText mTextUsername;
EditText mTextPassword;
Button mButtonLogin;
TextView mTextViewRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full
screen
setContentView(R.layout.activity_login);
mTextUsername = findViewById(R.id.edittext_username);
mTextPassword = findViewById(R.id.edittext_password);
mButtonLogin = findViewById(R.id.button_login);
mTextViewRegister = findViewById(R.id.textview_register);
mTextViewRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent registerIntent = new Intent(LoginActivity.this,
RegisterActivity.class);
startActivity(registerIntent);
}
});
}
}
答案 0 :(得分:1)
我测试了相同的代码,通过猜测我可以判断出您可能错拼了activity_login的名称(可能是您分配了不具有名为textview_register的文本视图的其他布局),或者是您没有名为RegisterActivity.class的活动