I am getting `NullPointerException` while setting `layout` from View class.
I want to access the view of a class at runtime. I have written code for ex. `TableView` class. In this class, I have set all the getters and setters of each control. 
But the problem which I am facing is when I run the activity I get the Null Pointer Exception in the `findViewById()` of the `Button` Control.

Can anyone help me to get out of it?
Thanks in advance.

This is my `XML` layout file of `TableActivity`:

```
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".TableView" >

    <TextView
        android:id="@+id/txtTableNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="67dp"
        android:text="Table No"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/edTableNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/txtTableNo"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:inputType="number" />

    <Button
        android:id="@+id/btnSaveTableMaster"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/edTableNo"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="76dp"
        android:text="Save" />

    <Button
        android:id="@+id/btnUploadTableData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnSaveTableMaster"
        android:layout_below="@+id/btnSaveTableMaster"
        android:layout_marginTop="56dp"
        android:text="Upload" />

</RelativeLayout>

```

The below file is of the View Class of `TableActivity`:

```
package com.bis.restaurant.kot.view;

import com.bis.restaurant.kot.R;

import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class TableView extends View{

    EditText edTableNo;
    Button btnSaveTableMaster,btnUploadTableData;
    Context con;
    public TableView(Context context) {
        super(context);
        this.con = context;
        findViewById(R.layout.activity_table_view);
        setEdTableNo(new EditText(con));
        setBtnSaveTableMaster((Button)findViewById(R.id.btnSaveTableMaster));
        setBtnUploadTableData((Button)findViewById(R.id.btnUploadTableData));
    }
    public EditText getEdTableNo() {
        return edTableNo;
    }
    public Button getBtnSaveTableMaster() {
        return btnSaveTableMaster;
    }
    public Button getBtnUploadTableData() {
        return btnUploadTableData;
    }
    public void setEdTableNo(EditText edTableNo) {
        this.edTableNo = edTableNo;
        //edTableNo.setWidth(LayoutParams.WRAP_CONTENT);
    }
    public void setBtnSaveTableMaster(Button btnSaveTableMaster) {
        this.btnSaveTableMaster = btnSaveTableMaster;
    }
    public void setBtnUploadTableData(Button btnUploadTableData) {
        this.btnUploadTableData = btnUploadTableData;
    }
}

```

The below file is the `TableActivity` from where the View is used.:

```
public class TableActivity extends Activity {

    /*EditText edTableNo;
    Button btnSaveTableMaster,btnUploadTableData;
    */String fileName;
    Date dt=new Date();
    Context con=this;
    ArrayList<String> csvHeaders;
    FileChooser filepath;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    final TableView tableView = new TableView(con);
    setContentView(tableView);
        /*edTableNo=(EditText)findViewById(R.id.edTableNo);
        btnSaveTableMaster=(Button)findViewById(R.id.btnSaveTableMaster);
        btnUploadTableData=(Button)findViewById(R.id.btnUploadTableData);
        */

    tableView.getBtnSaveTableMaster().setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(tableView.getEdTableNo()!=null && tableView.getEdTableNo().getText().toString().trim().length()>0 ){
                    TableMaster tableMaster=new TableMaster();
                    tableMaster.setCurTableDate(dt);
                    tableMaster.setTableNo(tableView.getEdTableNo().getText().toString());

                    TableDao tableDao=new TableDao(con);
                    Boolean flag=tableDao.addTableViewData(tableMaster);

                    if(flag){
                        Toast.makeText(con, "Data Saved Successfully.", Toast.LENGTH_LONG).show();
                    }

                    Intent i=new Intent(getApplicationContext(),WaiterActivity.class);

                    startActivity(i);
                    finish();
                }
            }
        });

```

I am getting `NullPointerException` on the following line:

**`tableView.getBtnSaveTableMaster().setOnClickListener(new OnClickListener())`**