java - 为什么我会收到错误 : cannot find symbol variable in R class

标签 java android r.java-file cannot-find-symbol

下面的源代码应该制作一张图片并显示在屏幕上。但是我得到了一些错误。 无法解析符号 'activity_fullscreen',同样适用于 imageView1dummy_buttonfullscreen_contentfullscreen_content_controls.

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        mVisible = true;
        mControlsView = findViewById(R.id.fullscreen_content_controls);
        mContentView = findViewById(R.id.fullscreen_content);


        // Set up the user interaction to manually show or hide the system UI.
        mContentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggle();
            }
        });

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.
        findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);//dummy abaendern


        //super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_fullscreen);
        this.imageView = (ImageView)this.findViewById(R.id.imageView1);
        Button photoButton = (Button) this.findViewById(R.id.dummy_button);
        photoButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(cameraIntent, CAMERA_REQUEST);
            }
        });


    }

那些是我的进口:

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Bitmap;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.content.Intent;
import android.widget.Button;
import android.widget.ImageView;
import android.R;

现在让我们看一下 activity_fullscreen.xml 缺少的部分肯定在那里。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
    android:background="#0099cc"
    tools:context="com.example.sasha.myapplication2.FullscreenActivity">

    <!-- The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc. -->
    <TextView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:text="@string/dummy_content"
        android:textColor="#33b5e5"
        android:textSize="50sp"
        android:textStyle="bold" />

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?metaButtonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="horizontal"
            tools:ignore="UselessParent">

            <Button
                android:id="@+id/dummy_button"
                style="?metaButtonBarButtonStyle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/dummy_button" />
            <ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:src="@drawable/icon" android:layout_width="wrap_content"></ImageView>

        </LinearLayout>
    </FrameLayout>

</FrameLayout>

我已经查看了 the following answer 中的建议. 据我所知,名称不包含任何非法字符。我也已经通过 File -> Invalidate Caches/Restart 重新启动了 android studio..

但我仍然没有找到解决问题的办法。怎么可能 R 可以解析而不是它的内容?欢迎任何想法。谢谢

最佳答案

你导入了错误的'R'

删除这个:

import android.R;

添加这个:

import com.yourCompany.yourApp.R;

关于java - 为什么我会收到错误 : cannot find symbol variable in R class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41793395/

相关文章:

java - 如何在各自的测试文件夹中为每个测试生成 cucumber.json (我使用的是 Cucumber 5,它使用 TestNG 进行并行执行)

java - 是否可以在所有操作系统上运行带有 java 的 Wrapped C++ 代码?

java - OrderBy + sum() + boolean 表达式

java - 安卓 : The Missing R

android - Hello World Android-错误创建

java - 使用 GET 在列标题中设置大标题

Android xml vs java 布局性能

java - Android 上的 I/O 基准测试

android - 如何在 Superpowered SDK 中并行应用过滤器

安卓 : R class stopped getting generated