java.lang.RuntimeException : Unable to start activity ComponentInfo for register and login 错误

标签 java android

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.earljames.register_login/com.example.earljames.register_login.Home}: java.lang.NullPointerException

这是我的主页代码。

public class  Home extends AppCompatActivity implements View.OnClickListener {

    Button bLogout;
    EditText etUsername, etName, etAge;

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

        etUsername = (EditText) findViewById(R.id.etUsername);
        etName = (EditText) findViewById(R.id.etName);
        etAge = (EditText) findViewById(R.id.etAge);
        bLogout = (Button) findViewById(R.id.bLogout);

        bLogout.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bLogout:
                startActivity(new Intent(this,Login.class));
                break;
        }
    }
}

Androidmanifest.xml

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

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".Home">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Login" />
    <activity
        android:name=".Register"
        android:label="@string/title_activity_register"
        android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

Activity_Register.xml

<TextView
    android:text="Name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/etName"
    android:layout_marginBottom="10dp"/>

<TextView
    android:text="Age"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/etAge"
    android:layout_marginBottom="10dp"/>

<TextView
    android:text="Username"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/etUsername"
    android:layout_marginBottom="10dp"/>

<TextView
    android:text="Password"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/etPassword"
    android:inputType="textPassword"
    android:layout_marginBottom="10dp"/>

<Button
    android:layout_width="match_parent"
    android:text="Register"
    android:id="@+id/bRegister"
    android:layout_height="wrap_content" />

最佳答案

可能我能看到的是你这个变量的问题

试试 HOME.this

写这行还是不行

Intent i = new Intent(Home.this,Ur new activity.class) i.setFlag(Intent.FLAG_NEWACTIVITY) 启动 Activity (i)

关于java.lang.RuntimeException : Unable to start activity ComponentInfo for register and login 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36964047/

相关文章:

java - Spark - 在字符串匹配后提取行并将其保存在 ArrayList 中

java - 使用 JNI 代替 JNA 调用原生代码?

java - Camera 2 API 问题,图像始终以横向模式显示

Android 弹出窗口全屏

android - 如何确定特定设备是否支持 SIM 卡硬件?

android - NestedScrollView & RecyclerView, onLongPress 事件

java - JAVA中SSL握手时如何获取ClientHello信息

java - 跨多个类使用 java.util.logging

android - Unity APK 大小比 Resources 中使用的大很多吗?

java - Android SQLite : Convert long to Date and back