Android Studio Kotlin Error Unsolved Reference

Asked 2 years ago, Updated 2 years ago, 83 views

It was working properly until the middle, but suddenly I got an Unsolved Reference error.There are about 6 Activity files, but R in R.layout.hogehoge_activity of all files turns red and gives an error.

I'm a beginner at Android Studio for the first two weeks.

The environment is
API 28 revision 6
emulator-5554 Android 9
Android Studio 3.1.4
SDK tools 26.1.1
↑Development Language Kotlin

There are many activity files, so I wrote MainActivity, build.gradle, and Manifest files that I would know about.

I looked it up on the Internet, but I couldn't find any useful information, so I'd like to ask for more information.

Write down the error.

FAILURE: Build failed with an exception.

* What was wrong:
Execution failed for task ':app:processDebugResources'.
>Failed to process resources, see aapt output above for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with -- info or -- debug option to get more log output. Run with -- scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
13 actionable tasks:1 executed, 12 up-to-date

First File MainActivity

package com.example.yusuke.mysql02

import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.preference.PreferenceManager
import android.view.View
import android.widget.EditText
import com.example.yusuke.mysql02.Global.globalusername
import com.example.yusuke.mysql02.R.id.username
import android.widget.TextView
import android.widget.Toast
import com.android.volley.Request
import com.android.volley.toolbox.StringRequest
// import com.example.yusuke.mysql02.Global.num
import kotlinx.android.synthetic.main.activity_main.*
import com.android.volley.Response
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.Volley
import org.json.JSONObject


classMainActivity:AppCompatActivity(){



    override fun onCreate (savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

    }

    val jsonobj = JSONObject()

    fun nextactivity (v:View) {

        jsonobj.put("username", username.text)
        jsonobj.put ("password", password.text)

       val URL = "http://www.example.com/registeractivity.php"
       value = Volley.newRequestQueue(this@MainActivity)


        val req = JsonObjectRequest(Request.Method.POST, URL, jsonobj,
                Response.Listener {
            response->

                    Global.globalexist=response.toString()

                },Response.ErrorListener{
           Global.globalexist="0"
        })

        queue.add(req)


        varnameetext: String=username.getText().toString()
        var passstext: String=password.getText().toString()

        Global.globalusername=nameetext
        Global.globalpassword=passtext

        valintent=Intent(this,RegisteredActivity::class.java)
        startActivity (intent)

    }

    fun loginactivity (v:View) {
        valintent=Intent(this,LoginActivity::class.java)
        startActivity (intent)
    }
}

Second file build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android{android{
    compileSdkVersion28
    defaultConfig {
        applicationId "com.example.yusuke.mysql02"
        minSdkVersion20
        targetSdkVersion28
        versionCode1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            miniEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree (dir: 'libs', include: ['*.jar')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation'com.android.support.test:runner:1.0.2'
    androidTestImplementation'com.android.support.test.espreso:espresso-core: 3.0.2'
    implementation'com.android.volley:volley:1.1.1'

}

Third File Manifest File

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.yusuke.mysql02">
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android: icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android: roundIcon="@mipmap/ic_launcher_round"
        android:supportRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".LoginActivity"/>
        <activity android:name=".RegisteredActivity"/>
        <activity android:name=".choseuserActivity"/>
        <activity android:name=".addfriend"/>
        <activity android:name=".Message"></activity>
    </application>

</manifest>

android kotlin

2022-09-29 21:25

1 Answers

If R is red in the Unsolved Reference, isn't it just multiple candidates for R?
Why don't you specify R in more detail or import it?
Like import com.example.yusuke.mysql02.R.


2022-09-29 21:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.