Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin Android Studio希望在成员已声明后进行成员声明_Kotlin - Fatal编程技术网

Kotlin Android Studio希望在成员已声明后进行成员声明

Kotlin Android Studio希望在成员已声明后进行成员声明,kotlin,Kotlin,这是我的第一个android应用程序,我正在尝试用一些文本填充textView对象 当我尝试将文本设置为已声明的TextView对象时: val textView = findViewById<TextView>(R.id.textView) textView.text = 'hello' val textView=findViewById(R.id.textView) textView.text='hello' 生成一个错误,该错误表示“期望成员声明” 安卓工作室似乎不承认这

这是我的第一个android应用程序,我正在尝试用一些文本填充textView对象

当我尝试将文本设置为已声明的TextView对象时:

val textView = findViewById<TextView>(R.id.textView)

textView.text = 'hello'
val textView=findViewById(R.id.textView)
textView.text='hello'
生成一个错误,该错误表示“期望成员声明”

安卓工作室似乎不承认这一声明。 rStudio中我的代码的图像链接(目前还不允许直接发布图像):

我试过: 1) 清理和重建项目。 2) 将textView设置为“hello”(双引号)和字符串变量

我可以在我的应用程序的其他活动中使用相同的过程将文本设置为textview对象,但我无法在此处执行此操作。我确信这对我来说很愚蠢,但我就是看不出来

请让我知道,如果有什么需要澄清或如果我需要提供更多的信息

package com.example.appzilla

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.TextView
import androidx.cardview.widget.CardView

class Place_Page : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.place_page)
    }
    val textView = findViewById<TextView>(R.id.textView)
    textView.text = 'hello'

    val place : Place = intent.getParcelableExtra("Extra_Place")


}
package com.example.appzilla
导入androidx.appcompat.app.appcompat活动
导入android.os.Bundle
导入android.view.view
导入android.widget.AdapterView
导入android.widget.TextView
导入androidx.cardview.widget.cardview
课程地点\页面:AppCompatActivity(){
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.place_页面)
}
val textView=findViewById(R.id.textView)
textView.text='hello'
val-place:place=intent.getParcelableExtra(“额外地点”)
}

或者如果它应该是一个字段:

class Place_Page : AppCompatActivity() {
    lateinit var textView: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.place_page)
        textView = findViewById<TextView>(R.id.textView)
        textView.text = 'hello'
    }
}
class Place\u页面:appcompativity(){
lateinit var textView:textView
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.place_页面)
textView=findViewById(R.id.textView)
textView.text='hello'
}
}

将文本视图行放入oncreate方法中。Findviewbyid只在setcontentview之后才起作用。

非常感谢您这么做。很高兴听到它。@Scottlocasio很乐意帮忙)除非您在AS方面有问题,否则不要使用
Android studio
标记。
val textView = findViewById<TextView>(R.id.textView)
textView.text = 'hello'
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.place_page)
    val textView = findViewById<TextView>(R.id.textView)
    textView.text = 'hello'
}
class Place_Page : AppCompatActivity() {
    lateinit var textView: TextView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.place_page)
        textView = findViewById<TextView>(R.id.textView)
        textView.text = 'hello'
    }
}