E.James E.James - 7 months ago 48
Java Question

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


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


Here's my code for my home page.

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" />



Answer

I guess that is something related to the activity_register xml. Please check that the Button id bLogout exists and it is spelled correctly.

Comments