title: Modify textView in a fragment from MainActivity using SharedPreferences (Kotlin)
body: <p>I have an issue with a project in Kotlin. I need to modify textViews in fragments but I cannot access those textView.
  The error I receive back is:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.example/com.example.example.MainActivity}: java.lang.IllegalStateException: emailSettingsText must not be null
  </code></pre>
  
  <p>In my MainActivity (where the fragment is) I tried this:</p>
  
  <pre><code>emailSettingsText.text = sharedPreferences.getString("EMAIL", "")
  </code></pre>
  
  <p>I tried also to create a var in my main activity:</p>
  
  <pre><code>var = emailVar = sharedPreferences.getString("EMAIL", "")
  </code></pre>
  
  <p>but I cannot change the text in the fragment.</p>
  
  <p>This is the fragment:</p>
  
  <pre><code>package com.example.example.ui.settings
  
  import android.os.Bundle
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.TextView
  import androidx.fragment.app.Fragment
  import androidx.lifecycle.ViewModelProviders
  import com.example.example.R
  import kotlinx.android.synthetic.main.activity_terms.*
  import kotlinx.android.synthetic.main.fragment_settings.*
  
  
  @Suppress("DEPRECATION")
  class SettingsFragment : Fragment() {
  
  
      override fun onCreateView(
          inflater: LayoutInflater,
          container: ViewGroup?,
          savedInstanceState: Bundle?
  
      ): View? {
  
          ViewModelProviders.of(this).get(SettingsViewModel::class.java)
  
  
  
  
          return inflater.inflate(R.layout.fragment_settings, container, false)
      }
  </code></pre>
  
  <p>}</p>
  
  <p>Is there any way to change a textView called emailShowSettingsText in the fragment?
  Thank u for any help.</p>
  
  <p>This is my activity code:</p>
  
  <pre><code>package com.example.example
  
  import android.content.Context
  import android.content.SharedPreferences
  import android.os.Bundle
  import android.provider.Settings
  import android.util.Log
  import android.widget.TextView
  import com.google.android.material.bottomnavigation.BottomNavigationView
  import androidx.appcompat.app.AppCompatActivity
  import androidx.fragment.app.FragmentTransaction
  import androidx.navigation.findNavController
  import androidx.navigation.ui.AppBarConfiguration
  import androidx.navigation.ui.setupWithNavController
  import com.example.example.ui.settings.SettingsFragment
  import kotlinx.android.synthetic.main.fragment_settings.*
  import kotlinx.android.synthetic.main.fragment_settings.view.*
  import kotlinx.android.synthetic.main.fragment_traffic.*
  
  class MainActivity : AppCompatActivity(), Communicator {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          val navView: BottomNavigationView = findViewById(R.id.nav_view)
  
          val sharedPreferences = getSharedPreferences("TOKEN_FILE", Context.MODE_PRIVATE)
  
          val navController = findNavController(R.id.nav_host_fragment)
  
          var dominioVal = sharedPreferences.getString("DOMINIO", "")
  
          AppBarConfiguration(
              setOf(
                  R.id.navigation_traffic, R.id.navigation_ipblocked, R.id.navigation_search_terms, R.id.navigation_settings
              )
          )
  
          navView.setupWithNavController(navController)
      }
  
  
  }
  </code></pre>