Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...