-2

On clicking a button In which I am Retrieving inserted data. But it shows null pointer Exception.

My app should show inserted data and the user enters data and time in an alert dialog box. But when I run my app crashes. I have check my logcat it showing following error

Java.lang.NullPointer Exception:Attempt to invoke a virtual method: 'aandroid.text.wideget.EditText().getText()'on a null object refrence at sana.com.Happymeal.Reservation$3.onClick(Reservation.java.98 I am a beginner and doing work in SQLite for the first time I have wasted 3 to 4 days on this error Please tell me the best solution.

<Here is Reservation classa>
    package sana.com.happymeal;

    import android.app.ActionBar;
    import android.app.DatePickerDialog;
    import android.app.TimePickerDialog;
    import android.database.Cursor;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import android.widget.TimePicker;
    import android.widget.DatePicker;
    import android.support.v7.widget.Toolbar;
    import android.app.AlertDialog;
    import android.widget.Toast;

    import java.util.Calendar;

    public class Reservation extends AppCompatActivity
    {
        Calendar clndr;
        Button Pick_Date,pick_time;
        EditText edDate,ed_firstname,ed_lastname,edTime,ed_email,edPassword,mem;
        Integer members;
        Button btn,btn_details, mBtnPickTime;
        DatePickerDialog datePickerDialog;
        TextView tv1, tv2, Time;
        TimePickerDialog tpd;
        DatabaseHelper databaseHelper;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_reservation);
            tv1 = (TextView) findViewById(R.id.res_table);
            tv2 = (TextView) findViewById(R.id.text2);
            mem = (EditText) findViewById(R.id.members);
            btn = (Button) findViewById(R.id.booking_btn);
            btn_details=(Button)findViewById(R.id.details);
            edDate = (EditText) findViewById(R.id.ed_date);
            Pick_Date = (Button) findViewById(R.id.btnPickDate);
            pick_time=(Button)findViewById(R.id.btnPickTime);
            edTime=(EditText)findViewById(R.id.ed_time);

            databaseHelper = new DatabaseHelper(this);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_item);


            AddData();
            viewAll();
            Pick_Date.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    clndr = Calendar.getInstance();
                    int day = clndr.get(Calendar.DAY_OF_MONTH);
                    int month = clndr.get(Calendar.MONTH);
                    int year = clndr.get(Calendar.YEAR);

                    datePickerDialog = new DatePickerDialog(Reservation.this, new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker datePicker, int mYear, int mMonth, int mDay) {
                            edDate.setText(mDay + "/" + (mMonth + 1) + "/" + mYear);
                        }
                    }, year, month, day);
                    datePickerDialog.show();
                }
            });
            Time = findViewById(R.id.ed_time);
            mBtnPickTime = findViewById(R.id.btnPickTime);
            mBtnPickTime.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    clndr = Calendar.getInstance();
                    int hour = clndr.get(Calendar.HOUR_OF_DAY);
                    int mint = clndr.get(Calendar.MINUTE);

                    tpd = new TimePickerDialog(Reservation.this, new TimePickerDialog.OnTimeSetListener() {
                        @Override
                        public void onTimeSet(TimePicker timePicker, int mhour, int mMint) {
                            Time.setText(mhour + ":" + mMint);
                        }
                    }, hour, mint, false);
                    tpd.show();
                }
            });

        }

        public void AddData() {
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Boolean isInserted= databaseHelper.InsertData(ed_firstname.getText().toString(),ed_lastname.getText().toString(),ed_email.getText().toString(),edPassword.getText().toString(),Integer.parseInt(mem.getText().toString()));
                    if(isInserted == true)
                        Toast.makeText(Reservation.this,"Data Inserted",Toast.LENGTH_LONG).show();
                    else
                        Toast.makeText(Reservation.this,"Data not Inserted",Toast.LENGTH_LONG).show();
                }
            });

        }


        public void viewAll() {

            btn_details.setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Cursor res = databaseHelper.getAllData();
                            if (res.getCount() == 0) {
                                // show message
                                showMessage("Error", "Nothing found");
                                return;
                            }

                            StringBuffer buffer = new StringBuffer();
                            while (res.moveToNext()) {
                                buffer.append("Id :" + res.getString(0) + "\n");
                                buffer.append("first_name:" + res.getString(1) + "\n");
                                buffer.append("Last_name :" + res.getString(2) + "\n");
                                buffer.append("Email :" + res.getString(3) + "\n");
                                buffer.append("Password :" + res.getString(4) + "\n");
                                buffer.append("Members :" + res.getString(5) + "\n");
                                buffer.append("Booked_at :" + res.getString(6) + "\n\n");
                            }

                            // Show all data
                            showMessage("Data", buffer.toString());
                        }
                    });
        }

            public void showMessage(String title , String Message){
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setCancelable(true);
                builder.setTitle(title);
                builder.setMessage(Message);
                builder.show();
            }

        }

Here I have database hepler class. In which i have insert function and i add query to select all data from table and show it. Database Helper

package sana.com.happymeal;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.Cursor;
import android.provider.MediaStore;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class
DatabaseHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "register.db";
    public static final String TABLE_NAME = "registeruser";
    public static final String ID = "id";
    public static final String first_name = "firstname";
    public static final String last_name = "lastname";
    public static final String Email="email";
    public static final String Password="password";
    public static final String no_Ofmem="members";
    public static final String Booked_at="date_time";


    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS registeruser(ID INTEGER PRIMARY KEY AUTOINCREMENT,first_name TEXT,last_name TEXT,Email TEXT,Password TEXT,no_Ofmem INTEGER ,Booked_at LONG)");

    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);

        }

        private String getDateTime(){
            SimpleDateFormat dateFormat=new SimpleDateFormat(
                    "dd-MM-YYY HH:mm:ss", Locale.getDefault()
            );
            Date date=new Date();
            return dateFormat.format(date);
        }
    public Boolean  InsertData(String firstname,String lastname,String email,String password,Integer members) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(first_name, firstname);
        contentValues.put(last_name, lastname);
        contentValues.put(Email, email);
        contentValues.put(Password, password);
        contentValues.put(no_Ofmem, members);
        contentValues.put(Booked_at, System.currentTimeMillis());
        long result = db.insert(TABLE_NAME, null, contentValues);
        if (result == -1) {
            return false;
        } else {
            return true;
        }
    }
        public Cursor getAllData() {
            SQLiteDatabase db = this.getWritableDatabase();
            Cursor res = db.rawQuery("select * from "+TABLE_NAME,null);
            return res;

      }



 > Login java file

    package sana.com.happymeal;
    import android.app.Notification;
    import android.content.Intent;
    import android.database.sqlite.SQLiteDatabase;
    import android.provider.ContactsContract;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.text.TextUtils;
    import android.util.Patterns;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    import android.database.Cursor;
    import android.content.Context;

    public class LoginActivity extends AppCompatActivity {
        EditText first_name;
        EditText last_name;
        EditText password;
        EditText re_enterpass;
        EditText email;
        Button signin;
        DatabaseHelper databaseHelper;
        SQLiteDatabase sqLiteDatabaseObj;
        String SQLiteDataBaseQueryHolder;
        Cursor cursor;
        String F_Result = "Not_Found";
        Boolean EditTextEmptyHolder;
        String FirstNameHolder,LastNameHolder, EmailHolder, PasswordHolder;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login);
            first_name = (EditText) findViewById(R.id.firstname);
            last_name = (EditText) findViewById(R.id.lastname);
            password = (EditText) findViewById(R.id.password);
            email = (EditText) findViewById((R.id.email));
            re_enterpass = (EditText) findViewById(R.id.confirm_password);
            databaseHelper = new DatabaseHelper(this);
            signin = (Button) findViewById(R.id.signinbtn);
            signin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Creating SQLite database if dose n't exists
                    SQLiteDataBaseBuild();

                    // Creating SQLite table if dose n't exists.
                    SQLiteTableBuild();
                    CheckEditTextStatus();

                    // Method to check Email is already exists or not.
                    CheckingEmailAlreadyExistsOrNot();

                    CheckFinalResult();
                    // Empty EditText After done inserting process.
                    EmptyEditTextAfterDataInsert();


                }
            });
        }

            public void SQLiteDataBaseBuild() {

                sqLiteDatabaseObj = openOrCreateDatabase(DatabaseHelper.DATABASE_NAME, Context.MODE_PRIVATE, null);

            }

            // SQLite table build method.
            public void SQLiteTableBuild() {

                sqLiteDatabaseObj.execSQL("CREATE TABLE IF NOT EXISTS " + DatabaseHelper.TABLE_NAME + "(" + DatabaseHelper.ID + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + DatabaseHelper.first_name + " VARCHAR, " + DatabaseHelper.last_name + " VARCHAR, " + DatabaseHelper.Email + " VARCHAR,"+DatabaseHelper.Password +"VARCHAR);");

            }

            // Insert data into SQLite database method.
            public void InsertDataIntoSQLiteDatabase() {

                // If editText is not empty then this block will executed.
                if (EditTextEmptyHolder == true) {

                    // SQLite query to insert data into table.
                    SQLiteDataBaseQueryHolder = "INSERT INTO " + DatabaseHelper.TABLE_NAME + " (firstname,lastname,email,password) VALUES('" + FirstNameHolder + "', '" + LastNameHolder + "', '" + EmailHolder +" ', + '"+PasswordHolder+"');";

                    // Executing query.
                    sqLiteDatabaseObj.execSQL(SQLiteDataBaseQueryHolder);

                    // Closing SQLite database object.
                    sqLiteDatabaseObj.close();

                    // Printing toast message after done inserting.
                    Toast.makeText(LoginActivity.this, "User Registered Successfully", Toast.LENGTH_LONG).show();

                }
                // This block will execute if any of the registration EditText is empty.
                else {

                    // Printing toast message if any of EditText is empty.
                    Toast.makeText(LoginActivity.this, "Please Fill All The Required Fields.", Toast.LENGTH_LONG).show();


                }
            }

        public void EmptyEditTextAfterDataInsert(){

            first_name.getText().clear();

            last_name.getText().clear();
            email.getText().clear();
            password.getText().clear();
            re_enterpass.getText().clear();

        }
        public void CheckEditTextStatus(){

            // Getting value from All EditText and storing into String Variables.
            FirstNameHolder = first_name.getText().toString() ;
            EmailHolder = email.getText().toString();
            PasswordHolder = password.getText().toString();

            if(TextUtils.isEmpty(FirstNameHolder) ||TextUtils.isEmpty(LastNameHolder)|| TextUtils.isEmpty(EmailHolder) || TextUtils.isEmpty(PasswordHolder)){
                EditTextEmptyHolder = false ;
            }
            else {
                EditTextEmptyHolder = true ;
            }
        }
        public void CheckingEmailAlreadyExistsOrNot() {

            sqLiteDatabaseObj=databaseHelper.getWritableDatabase();
            // Adding search email query to cursor.
            cursor= sqLiteDatabaseObj.query(DatabaseHelper.TABLE_NAME, null, " " + DatabaseHelper.Email + "=?", new String[]{EmailHolder}, null, null, null);

            while (cursor.moveToNext()) {

                if (cursor.isFirst()) {

                    cursor.moveToFirst();

                    // If Email is already exists then Result variable value set as Email Found.
                    F_Result = "Email Found";

                    // Closing cursor.
                    cursor.close();


                }
                CheckFinalResult();
            }

            Intent intent=new Intent(LoginActivity.this,Restraunts.class);
            startActivity(intent);

        }
            // Checking result
            public void CheckFinalResult(){

                // Checking whether email is already exists or not.
                if(F_Result.equalsIgnoreCase("Email Found"))
                {

                    // If email is exists then toast msg will display.
                    Toast.makeText(LoginActivity.this,"Email Already Exists",Toast.LENGTH_LONG).show();

                }
                else {

                    // If email already dose n't exists then user registration details will entered to SQLite database.
                    InsertDataIntoSQLiteDatabase();

                }

                F_Result = "Not_Found" ;

            }
        }






> Login xml file

    <?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:background="@drawable/background"
        android:orientation="vertical"
        android:gravity="center_horizontal">
        <EditText
            android:layout_width="290dp"
            android:layout_height="40dp"
            android:hint="@string/firstname"
            android:layout_marginTop="140dp"
            android:textColor="#000000"
            android:id="@+id/firstname"
            android:background="#ffffff"/>
        <EditText
            android:layout_width="290dp"
            android:layout_height="40dp"
            android:hint="@string/lastname"
            android:layout_marginTop="20dp"
            android:textColor="#000000"
            android:background="#ffffff"
            android:id="@+id/lastname"/>
        <EditText
            android:layout_width="290dp"
            android:layout_height="40dp"
            android:layout_marginTop="20dp"
            android:textColor="#000000"
            android:hint="@string/email"
            android:background="#ffffff"
            android:id="@+id/email"/>
        <EditText
            android:layout_width="290dp"
            android:layout_height="40dp"
            android:hint="@string/password"
            android:background="#ffffff"
            android:textColor="#000000"
            android:id="@+id/password"
            android:layout_marginTop="20dp"/>
        <EditText
            android:layout_width="290dp"
            android:layout_height="40dp"
            android:hint="@string/confirm_password"
            android:background="#ffffff"
            android:textColor="#000000"
            android:id="@+id/confirm_password"
            android:layout_marginTop="20dp"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Sign in"
            android:background="#F44336"
            android:layout_marginTop="20dp"
            android:id="@+id/signinbtn"/>



    </LinearLayout>

> Login Java file
package sana.com.happymeal;
import android.app.Notification;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.database.Cursor;
import android.content.Context;

public class LoginActivity extends AppCompatActivity {
    EditText first_name;
    EditText last_name;
    EditText password;
    EditText re_enterpass;
    EditText email;
    Button signin;
    DatabaseHelper databaseHelper;
    SQLiteDatabase sqLiteDatabaseObj;
    String SQLiteDataBaseQueryHolder;
    Cursor cursor;
    String F_Result = "Not_Found";
    Boolean EditTextEmptyHolder;
    String FirstNameHolder,LastNameHolder, EmailHolder, PasswordHolder;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        first_name = (EditText) findViewById(R.id.firstname);
        last_name = (EditText) findViewById(R.id.lastname);
        password = (EditText) findViewById(R.id.password);
        email = (EditText) findViewById((R.id.email));
        re_enterpass = (EditText) findViewById(R.id.confirm_password);
        databaseHelper = new DatabaseHelper(this);
        signin = (Button) findViewById(R.id.signinbtn);
        signin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Creating SQLite database if dose n't exists
                SQLiteDataBaseBuild();

                // Creating SQLite table if dose n't exists.
                SQLiteTableBuild();
                CheckEditTextStatus();

                // Method to check Email is already exists or not.
                CheckingEmailAlreadyExistsOrNot();

                CheckFinalResult();
                // Empty EditText After done inserting process.
                EmptyEditTextAfterDataInsert();


            }
        });
    }

        public void SQLiteDataBaseBuild() {

            sqLiteDatabaseObj = openOrCreateDatabase(DatabaseHelper.DATABASE_NAME, Context.MODE_PRIVATE, null);

        }

        // SQLite table build method.
        public void SQLiteTableBuild() {

            sqLiteDatabaseObj.execSQL("CREATE TABLE IF NOT EXISTS " + DatabaseHelper.TABLE_NAME + "(" + DatabaseHelper.ID + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + DatabaseHelper.first_name + " VARCHAR, " + DatabaseHelper.last_name + " VARCHAR, " + DatabaseHelper.Email + " VARCHAR,"+DatabaseHelper.Password +"VARCHAR);");

        }

        // Insert data into SQLite database method.
        public void InsertDataIntoSQLiteDatabase() {

            // If editText is not empty then this block will executed.
            if (EditTextEmptyHolder == true) {

                // SQLite query to insert data into table.
                SQLiteDataBaseQueryHolder = "INSERT INTO " + DatabaseHelper.TABLE_NAME + " (firstname,lastname,email,password) VALUES('" + FirstNameHolder + "', '" + LastNameHolder + "', '" + EmailHolder +" ', + '"+PasswordHolder+"');";

                // Executing query.
                sqLiteDatabaseObj.execSQL(SQLiteDataBaseQueryHolder);

                // Closing SQLite database object.
                sqLiteDatabaseObj.close();

                // Printing toast message after done inserting.
                Toast.makeText(LoginActivity.this, "User Registered Successfully", Toast.LENGTH_LONG).show();

            }
            // This block will execute if any of the registration EditText is empty.
            else {

                // Printing toast message if any of EditText is empty.
                Toast.makeText(LoginActivity.this, "Please Fill All The Required Fields.", Toast.LENGTH_LONG).show();


            }
        }

    public void EmptyEditTextAfterDataInsert(){

        first_name.getText().clear();

        last_name.getText().clear();
        email.getText().clear();
        password.getText().clear();
        re_enterpass.getText().clear();

    }
    public void CheckEditTextStatus(){

        // Getting value from All EditText and storing into String Variables.
        FirstNameHolder = first_name.getText().toString() ;
        EmailHolder = email.getText().toString();
        PasswordHolder = password.getText().toString();

        if(TextUtils.isEmpty(FirstNameHolder) ||TextUtils.isEmpty(LastNameHolder)|| TextUtils.isEmpty(EmailHolder) || TextUtils.isEmpty(PasswordHolder)){
            EditTextEmptyHolder = false ;
        }
        else {
            EditTextEmptyHolder = true ;
        }
    }
    public void CheckingEmailAlreadyExistsOrNot() {

        sqLiteDatabaseObj=databaseHelper.getWritableDatabase();
        // Adding search email query to cursor.
        cursor= sqLiteDatabaseObj.query(DatabaseHelper.TABLE_NAME, null, " " + DatabaseHelper.Email + "=?", new String[]{EmailHolder}, null, null, null);

        while (cursor.moveToNext()) {

            if (cursor.isFirst()) {

                cursor.moveToFirst();

                // If Email is already exists then Result variable value set as Email Found.
                F_Result = "Email Found";

                // Closing cursor.
                cursor.close();


            }
            CheckFinalResult();
        }

        Intent intent=new Intent(LoginActivity.this,Restraunts.class);
        startActivity(intent);

    }
        // Checking result
        public void CheckFinalResult(){

            // Checking whether email is already exists or not.
            if(F_Result.equalsIgnoreCase("Email Found"))
            {

                // If email is exists then toast msg will display.
                Toast.makeText(LoginActivity.this,"Email Already Exists",Toast.LENGTH_LONG).show();

            }
            else {

                // If email already dose n't exists then user registration details will entered to SQLite database.
                InsertDataIntoSQLiteDatabase();

            }

            F_Result = "Not_Found" ;

        }
    }

2 Answers2

0

I guess you get the exception in the following line inside AddData().

// you got the exception in below line cause  ed_firstname, ed_lastname, ed_email, and edPassword are not initialized.
Boolean isInserted= databaseHelper.InsertData(ed_firstname.getText().toString(),ed_lastname.getText().toString(),ed_email.getText().toString(),edPassword.getText().toString(),Integer.parseInt(mem.getText().toString()));

UPDATE

Yes, you have not used firstname, lastname, email and edPassword in activity_reservation. But the problem is you used these in your Reservation activity.

public class Reservation extends AppCompatActivity
    {
        Calendar clndr;
        Button Pick_Date,pick_time;

        // why you declear ed_firstname, ed_lastname, ed_email and edPassword in below, these are not used in activity_reservation
        // Though its not the reason you got exception
        EditText edDate,ed_firstname,ed_lastname,edTime,ed_email,edPassword,mem;
......

You got the exception in the following method in your Reservation activity. Read my comments

public void AddData() {
      btn.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {

                 // Here you try to get value from ed_firstname, ed_lastname, ed_email, and edPassword
                 // these fields are not initialized yet that's why you got null pointer exception
                 // if you initialize these fields that won't work cause these fields are not used in `activity_reservation`.
                 Boolean isInserted= databaseHelper.InsertData(ed_firstname.getText().toString(),ed_lastname.getText().toString(),ed_email.getText().toString(),edPassword.getText().toString(),Integer.parseInt(mem.getText().toString()));
                 if(isInserted == true)
                     Toast.makeText(Reservation.this,"Data Inserted",Toast.LENGTH_LONG).show();
                 else
                     Toast.makeText(Reservation.this,"Data not Inserted",Toast.LENGTH_LONG).show();
         }
   });
}

Solution

You can't initialize and use ed_firstname, ed_lastname, ed_password and ed_email in Reservation activity, cause these are not used in activity_reservation.

If you need user's first name, last name, email and password in your Reservation activity, then you can follow any of the following ways.

Passing data between Activities using Intents

OR

Using shared preferences

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Jakir Hossain
  • 3,830
  • 1
  • 15
  • 29
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/199481/discussion-on-answer-by-jakir-hossain-i-am-retriveing-my-insert-function-in-data). – Samuel Liew Sep 15 '19 at 10:30
0

I have checked your code and found that there is now view assigned with variables ed_email, ed_firstname and ed_lastname.

So first define view with findViewById(...) and assign them with those variables in onCreate() method.

Define below lines in onCreate() method of your activity file(Java file, not your layout file).

ed_firstname = (EditText)findViewById(R.id.{id_of_firstname});
ed_lastname = (EditText)findViewById(R.id.{id_of_lastname});
ed_email = (EditText)findViewById(R.id.{id_of_email});
DHAVAL A.
  • 2,251
  • 2
  • 12
  • 27
  • @SanaNasir I think you are not getting us. You just need to initialise your variable with proper view in your activity's java file, not in your layout file which have `.xml` format. I have updated my answer please check that, and make changes as per that. – DHAVAL A. Sep 14 '19 at 04:11
  • No Ihave used these lines in java file in on create method actually the problem is Ihave not used these in xml .In reservation activity i have not firstname edit text,,edlastname,ed email I have these in login activity and from there I want to display inserted data on a click which is in reservation actiivty which I am doing wrong – Sana Nasir Sep 14 '19 at 05:18
  • Okay. So you know you are doing wrong. So have you find solution for that? – DHAVAL A. Sep 14 '19 at 05:22
  • I want to display inserted data on clicking a button But dont know How to do that I have login activity after login it shows restraunts lists in a listview and after clicking on any list item it shows reservation activity then after sleting date and time on clicking book button it should show user name email date and time in alert dailouge box plz suggest how to do this? – Sana Nasir Sep 14 '19 at 07:45
  • That is your issue. To solve your issue, after selecting date and time, on click of book button first retrieve that values from selection, and then create intent with these data(using `putExtra()` method). And navigate to target screen and retrieve that value on target screen using `getIntent().getStringExtra()` method. – DHAVAL A. Sep 15 '19 at 03:26
  • You can also refer solution section of @Jakir Hossain's answer. – DHAVAL A. Sep 15 '19 at 03:28