Trying to setOnClickListener for TextView not in main layout <p>I have a TextView that I am turning into a button. The TextView actually lives on a secondary layout.</p> <pre><code> protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.history); </code></pre> <p>this is the main layout here "R.layout.history"</p> <p>That loads a bunch of results in a ListAdapter and each result is displayed using R.layout.card_background</p> <p>I am trying to initialize and set the setOnClickListener for a TextView located on R.Layout.card_background but I am getting a nullPointerException.</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.history); Typeface tf = Typeface.createFromAsset(getAssets(),"Roboto-Light.ttf"); ListView listContent = (ListView) findViewById(android.R.id.list); TextView history = (TextView) findViewById(R.id.history); history.setTypeface(tf); Cursor cursor = db.getAllLogs(); Log.d("history.java", "finished Cursor cursor = db.getAllLogs();"); String[] from = {"_id", "dd", "gg", "ppg", "odo"}; int[] to = {deleteVal, R.id.cardDate, R.id.cardG, R.id.cardP, R.id.cardM}; ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.card_background, cursor, from, to); listContent.setAdapter(adapter); TextView cardDelete = (TextView) findViewById(R.id.cardDelete); cardDelete.setOnClickListener(new OnClickListener() { @Override public void onClick(View v){ } }); } </code></pre> <p>Any idea how I can set that and stop getting the NPE?</p> <p>Thanks</p>