admin管理员组文章数量:1318156
In my first app using Android Studio and Kotlin I still get errors for Unresolved reference
It's the only 6 errors left.
How could I fix this? I followed a sample guide to place the files so far.
activity_main.xml is in
C:\Users\D 11\AndroidStudioProjects\positionapp\app\src\main\res\layout\
starting lines:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=";
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Ein"
android:textOff="Aus" />
<EditText
android:id="@+id/editText_dt"
android:layout_width="match_parent"
android:layout_height="59dp"
android:hint="dt in Minuten oder Sekunden" />
<EditText
android:id="@+id/editText_tnr"
android:layout_width="match_parent"
android:layout_height="61dp"
android:hint="tnr" />
...
MainActivity.kt is in
C:\Users\D 11\AndroidStudioProjects\positionapp\app\src\main\java\com\example\positionapp\
lines 36 to 46
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
locationViewModel = ViewModelProvider(this).get(LocationViewModel::class.
java
)
toggleButton = findViewById(R.id.toggleButton)
editTextDt = findViewById(R.id.editText_dt)
editTextTnr = findViewById(R.id.editText_tnr)
editTextCdz = findViewById(R.id.editText_cdz)
scrollableText = findViewById(R.id.scrollableText)
...
Android Studio output
...
> Task :app:compileDebugKotlin FAILED
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:38:26 Unresolved reference 'layout'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:42:39 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:43:37 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:44:38 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:45:38 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:46:41 Unresolved reference 'id'.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing .jetbrains.kotlinpilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
I find my suggestions to use Clean and Rebuild Project, the latter of the two isn't in my version of Android Studio, and I can't find the option to re-add it in the modifying menu for the tool bars. How to select this option?
In my first app using Android Studio and Kotlin I still get errors for Unresolved reference
It's the only 6 errors left.
How could I fix this? I followed a sample guide to place the files so far.
activity_main.xml is in
C:\Users\D 11\AndroidStudioProjects\positionapp\app\src\main\res\layout\
starting lines:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Ein"
android:textOff="Aus" />
<EditText
android:id="@+id/editText_dt"
android:layout_width="match_parent"
android:layout_height="59dp"
android:hint="dt in Minuten oder Sekunden" />
<EditText
android:id="@+id/editText_tnr"
android:layout_width="match_parent"
android:layout_height="61dp"
android:hint="tnr" />
...
MainActivity.kt is in
C:\Users\D 11\AndroidStudioProjects\positionapp\app\src\main\java\com\example\positionapp\
lines 36 to 46
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
locationViewModel = ViewModelProvider(this).get(LocationViewModel::class.
java
)
toggleButton = findViewById(R.id.toggleButton)
editTextDt = findViewById(R.id.editText_dt)
editTextTnr = findViewById(R.id.editText_tnr)
editTextCdz = findViewById(R.id.editText_cdz)
scrollableText = findViewById(R.id.scrollableText)
...
Android Studio output
...
> Task :app:compileDebugKotlin FAILED
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:38:26 Unresolved reference 'layout'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:42:39 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:43:37 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:44:38 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:45:38 Unresolved reference 'id'.
e: file:///C:/Users/D%2011/AndroidStudioProjects/positionapp/app/src/main/java/com/example/positionapp/MainActivity.kt:46:41 Unresolved reference 'id'.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing .jetbrains.kotlinpilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
I find my suggestions to use Clean and Rebuild Project, the latter of the two isn't in my version of Android Studio, and I can't find the option to re-add it in the modifying menu for the tool bars. How to select this option?
Share Improve this question asked Jan 22 at 16:15 Bill2022Bill2022 399 bronze badges 3 |1 Answer
Reset to default 0In my only Kotlin file MainActivity.kt
the line
package com.example.positionapp
at the start was missing.
In the AndroidManifest.xml
file there was missing
package="com.example.smspositionsenderandreceiver"
within the <manifest ...
tag.
本文标签: androidHow to solve the errors of quotUnresolved referencequotStack Overflow
版权声明:本文标题:android - How to solve the errors of "Unresolved reference"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742034124a2417012.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
import
statements in MainActivity. – tyg Commented Jan 22 at 16:34R
instead of using the classandroid.R
? – k314159 Commented Jan 22 at 17:02