-1

when run my app on android emulator its show unfortunately app stop message

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

      Button blogin;
      EditText etusername,etpassword;
     TextView registerlink;

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

        etusername=(EditText) findViewById(R.id.uname);
        etpassword=(EditText) findViewById(R.id.upassword);
        blogin=(Button) findViewById(R.id.blogin);
        registerlink=(TextView) findViewById(R.id.bregister);
        blogin.setOnClickListener(this);
        registerlink.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.blogin:

                break;
            case R.id.bregister:
                startActivity(new Intent(this,RegisterActivity.class));
                break;
        }
    }
}

Xml coding for your reference. Logs shows a Nullpointer exceptions

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:padding="10dp"
    android:layout_height="match_parent">

<EditText
    android:id="@+id/uname"
    android:layout_width="match_parent"
    android:hint="@string/unamehint"
    android:layout_marginBottom="10dp"
    android:layout_height="wrap_content" />

    <EditText
        android:id="@+id/upassword"
        android:inputType="textPassword"
        android:layout_width="match_parent"
        android:hint="@string/upasswordhint"
        android:layout_marginBottom="10dp"
        android:layout_height="wrap_content" />
    <Button
        android:id="@+id/blogin"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content"
        android:layout_marginBottom="10dp"
        android:text="@string/buttonname"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/register"
        android:text="New User/Register"
        android:textStyle="bold"
        android:layout_gravity="center_horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

LOGCAT

254 9565-9565/com.example.prakash.aclientz E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.prakash.aclientz, PID: 9565
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.prakash.aclientz/com.example.prakash.aclientz.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.interna
USER9561
  • 1,084
  • 3
  • 15
  • 41
Prakash Samy
  • 81
  • 1
  • 3
  • 15

1 Answers1

0

R.id.bregister is not part in the xml file. Please check out once again give the R.id.register to the textView