0

I am new in android development. I'm trying to make a simple login and registration form. I have a TextView 'Sign up' which basically takes the user to the registerActivity when clicked on, but when everytime when i click on the sign up textView it crashes my app. I have searched for the solutions but i can't seem to figure out whats causing the crash.

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);

        }
    });

}
}
Raiyu
  • 101
  • 10
  • 4
    Please attach error log! – pa1.Shetty Apr 13 '19 at 10:17
  • You will most likely won't get answered without posting your error log. – Tamir Abutbul Apr 13 '19 at 10:17
  • uninstall the app and install again, the it should work fine – Sandeep Malik Apr 13 '19 at 10:21
  • 1
    I tested same code, Its's working fine, by guessing i can tell that you may misspelled name of `activity_login` (may be you assigned different layout which doesnot have text view named `textview_register`. or may be you dont have activity named RegisterActivity.class ,we can only guess unless you povide logcat. – pa1.Shetty Apr 13 '19 at 10:37
  • This code seems fine, Most probably the issue is in the next Activity you starting LoginActivity. Yes @PavanShetty is right, we cannot give actual answer until you attach error log. – Asad Ali Choudhry Apr 13 '19 at 11:01
  • @PavanShetty Thanks that's exactly what the problem was. I figured that out when i was re-checking everything. Can you add this to a separate answer so that i can select yours. – Raiyu Apr 13 '19 at 11:02
  • @Raiyu So what was the mistake? (out of my two guessings) – pa1.Shetty Apr 13 '19 at 11:07
  • I had setContentView(R.layout.activity_login) on RegisterActivity.java which i copied from LoginActivity.java and forgot to re-assign it to activity_register.xml. – Raiyu Apr 13 '19 at 11:12

1 Answers1

1

I tested same code, Its's working fine, by guessing i can tell that you may misspelled name of activity_login (may be you assigned different layout which doesnot have text view named textview_register) or may be you dont have activity named RegisterActivity.class.

pa1.Shetty
  • 401
  • 3
  • 16