Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

android - Kotlin: createDisableExceptionQarthFile method fail

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Gradle is ok, but page "Start" crashes ??.

get PatchStore::createDisableExceptionQarthFile method fail.
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.basic, PID: 13619
    kotlin.UninitializedPropertyAccessException: lateinit property binding has not been initialized
        at com.example.basic.Start.onViewCreated(Start.kt:56)

Line 56 is this: binding.textView.setText("Hello World")

So... I'm going to read tutorials which you linked here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...