title: Null Reference Exception when trying to access any of the textView elements in XML
body: <p>I'm new to Android Studio, Kotlin and XML. Yesterday, all my code worked fine. Today, one of my scripts is broken. I've searched the web for answers but none of them fit my situation.</p>
  
  <p>The Issue:
  Whenever I run my app, I get a NullPointerException error, from the code </p>
  
  <pre><code>productTextView.append("Product: ${it.name}\nOwner: ${it.owner}\nYear Purchased: ${it.yearPurchased}\nPrice: ${it.price}\n\n")
  </code></pre>
  
  <p>All the ID's match up and it works on other parts of the app.</p>
  
  <p>Heres my Kotlin code:</p>
  
  <pre><code>package com.example.myapplicationtutorialseries
  
  import android.content.Context
  import android.content.Intent
  import android.os.Bundle
  import androidx.appcompat.app.AppCompatActivity
  
  import kotlinx.android.synthetic.main.activity_main.*
  import kotlinx.android.synthetic.main.content_main.*
  
  class MainActivity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          setSupportActionBar(toolbar)
         fab.setOnClickListener {
              startActivity(Intent(this, AddProductActivity::class.java))
         }
          val preferences = getSharedPreferences("database", Context.MODE_PRIVATE)
          val savedName = preferences.getString("savedProductName", "This Value Doesn't Exist.")
          //d("Will", "Saved message is: $savedName")
          //lastSavedProduct.text = savedName
  
          val products = listOf(
              Product("Google Home Mini", "Will", 2019, 69.99),
              Product("Galaxy A40", "Will", 2019, 139.50),
              Product("Monitor", "Will", 2020, 160.00),
              Product("Amazon Fire", "Will", 2019, 25.00)
          )
          var totalCost = 0.0
          products.forEach{
              productTextView.append("Product: ${it.name}\nOwner: ${it.owner}\nYear Purchased: ${it.yearPurchased}\nPrice: ${it.price}\n\n")
              totalCost += it.price
          }
          //lastSavedProduct.text = "Total Cost: $totalCost"
      }
  }
  </code></pre>
  
  <p>Heres my XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/ConstraintLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
      &lt;TextView
          android:id="@+id/productTextView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginStart="16dp"
          android:layout_marginTop="16dp"
          android:text="TextView"
          android:verticalScrollbarPosition="defaultPosition"
          android:visibility="visible"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>