title: Access Database Handler Inside Fragment
body: <p>I am trying to access database Handler inside a <code>fragment</code> but its throwing me this error <code>does not have companion object error</code>. I tried database handler query and its working fine. Any help is appreciated.</p>
  
  <p><strong>Language Used</strong></p>
  
  <pre><code>Kotlin
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>class OneFragment : Fragment() {
  
       companion object
  {
  //Error in the below context
      var db=TestDatabaseHandler(Context)
  }
  
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {
      {
  
      var a=db.readData()
  
      }
  
      }
  </code></pre>