I'm trying dynamically set a text to the layout.
Example code:
Start.kt:
import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Context.LOCATION_SERVICE
import android.content.pm.PackageManager
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.example.basic.databinding.StartBinding
class Start : Fragment() {
override fun onCreate(savedInstanceState: Bundle?){
super.onCreate(savedInstanceState)
val binding : StartBinding = setContentView(MainActivity(), R.layout.start)
binding.textView.setText("Hello World")
}
}
start.xml:
<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"
tools:context=".Start">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:text="Current GPS Location"
android:textColor="#000"
android:textSize="30sp"
android:textStyle="bold" />
...
Gradle build ends ok but application crashes with this error when I open this page at my mobile phone:
[qarth_debug:] get PatchStore::createDisableExceptionQarthFile method fail.
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
How to repair it?
question from:
https://stackoverflow.com/questions/65651876/kotlin-createdisableexceptionqarthfile-method-fail 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…