R.id.main выдает мне красную ошибку, не может разрешить символ main в MainActivity.java ⇐ Android
R.id.main выдает мне красную ошибку, не может разрешить символ main в MainActivity.java
I'm using Android Studio for the first time. I'm following a tutorial online to build a calculator, and I'm trying to run my program through the emulator. But when I run it, I get the error message, "Cannot find symbol variable id".
I read through a lot of questions and answers trying to find the exact problem, but the closest I found was that in "R.id.main", the 'main' part should be somehow tied to my activity_main file, but I don't know how. I know some were saying to use "android:id" but in the tutorial, the instructor hadn't done anything with ids yet. So I don't know if it's because I somehow saved a file in a wrong folder.
I tried doing a Clean Build as I saw in one solution to someone else's related issue, but it didn't help. The program just gave the same error. Here is the compiler error:
C:\Users\using\Desktop\Android Projects\BMICalculator\app\src\main\java\com\miramichelle\bmicalculator\MainActivity.java:18: error: cannot find symbol ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { ^ symbol: variable id location: class R My code is:
MainActivity.java
package com.miramichelle.bmicalculator; import android.os.Bundle; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); } } activity_main.xml
Источник: https://stackoverflow.com/questions/780 ... ivity-java
I'm using Android Studio for the first time. I'm following a tutorial online to build a calculator, and I'm trying to run my program through the emulator. But when I run it, I get the error message, "Cannot find symbol variable id".
I read through a lot of questions and answers trying to find the exact problem, but the closest I found was that in "R.id.main", the 'main' part should be somehow tied to my activity_main file, but I don't know how. I know some were saying to use "android:id" but in the tutorial, the instructor hadn't done anything with ids yet. So I don't know if it's because I somehow saved a file in a wrong folder.
I tried doing a Clean Build as I saw in one solution to someone else's related issue, but it didn't help. The program just gave the same error. Here is the compiler error:
C:\Users\using\Desktop\Android Projects\BMICalculator\app\src\main\java\com\miramichelle\bmicalculator\MainActivity.java:18: error: cannot find symbol ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { ^ symbol: variable id location: class R My code is:
MainActivity.java
package com.miramichelle.bmicalculator; import android.os.Bundle; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); EdgeToEdge.enable(this); setContentView(R.layout.activity_main); ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); } } activity_main.xml
Источник: https://stackoverflow.com/questions/780 ... ivity-java
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Я хочу изменить путь android:name=".MainActivity" на "settings.MainActivity"
Anonymous » » в форуме JAVA - 0 Ответы
- 119 Просмотры
-
Последнее сообщение Anonymous
-