java - 错误依然存在~ "fullscreen_content_controls cannot be resolved or is not a field"

标签 java android eclipse

我是一个菜鸟 android 开发者,在尝试创建一个打开新布局的按钮时遇到了一些问题。当我这样做时,我遇到了一些错误,无论我尝试什么都不会消失。作为回应,我复制了我从原始结构更改的大部分 xml 文件和 java 文件,并将它们添加到一个新项目中,以为我所有的错误都会消失。我真的需要一些帮助,我无法告诉你我被这个小错误困住了多久。我附上了主要的 FullScreenActivity.java、activity_main.xml、Android Manifest 和错误消息。提前感谢你们的帮助,我真的很感激! c:

全屏 Activity .java ~

package sehej.android.doge;
import sehej.android.doge.util.SystemUiHider;
import sehej.android.doge.R;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;

public class FullscreenActivity extends Activity {
    /**
     * Whether or not the system UI should be auto-hidden after
     * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
     */
    private static final boolean AUTO_HIDE = true;

    /**
     * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
     * user interaction before hiding the system UI.
     */
    private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

    /**
     * If set, will toggle the system UI visibility upon interaction. Otherwise,
     * will show the system UI visibility upon interaction.
     */
    private static final boolean TOGGLE_ON_CLICK = true;

    /**
     * The flags to pass to {@link SystemUiHider#getInstance}.
     */
    private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

    /**
     * The instance of the {@link SystemUiHider} for this activity.
     */
    private SystemUiHider mSystemUiHider;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    ****    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    ****    final View contentView = findViewById(R.id.fullscreen_content);

        // Set up an instance of SystemUiHider to control the system UI for
        // this activity.
        mSystemUiHider = SystemUiHider.getInstance(this, contentView,
                HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                    // Cached values.
                    int mControlsHeight;
                    int mShortAnimTime;

                    @Override
                    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                    public void onVisibilityChange(boolean visible) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                            // If the ViewPropertyAnimator API is available
                            // (Honeycomb MR2 and later), use it to animate the
                            // in-layout UI controls at the bottom of the
                            // screen.
                            if (mControlsHeight == 0) {
                                mControlsHeight = controlsView.getHeight();
                            }
                            if (mShortAnimTime == 0) {
                                mShortAnimTime = getResources().getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView
                                    .animate()
                                    .translationY(visible ? 0 : mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        } else {
                            // If the ViewPropertyAnimator APIs aren't
                            // available, simply show or hide the in-layout UI
                            // controls.
                            controlsView.setVisibility(visible ? View.VISIBLE
                                    : View.GONE);
                        }

                        if (visible && AUTO_HIDE) {
                            // Schedule a hide().
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });

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

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.


    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

        // Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);
    }

    /**
     * Touch listener to use for in-layout UI controls to delay hiding the
     * system UI. This is to prevent the jarring behavior of controls going away
     * while interacting with activity UI.
     */
    View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (AUTO_HIDE) {
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            return false;
        }
    };

    Handler mHideHandler = new Handler();
    Runnable mHideRunnable = new Runnable() {
        @Override
        public void run() {
            mSystemUiHider.hide();
        }
    };

    /**
     * Schedules a call to hide() in [delay] milliseconds, canceling any
     * previously scheduled calls.
     */
    private void delayedHide(int delayMillis) {
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable, delayMillis);
    }
}

activity_main.xml~

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/grass"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:padding="20sp"
    app:textAlignment="center"
    tools:context=".MainActivity" >

    <requestFocus
        app:layout_width="wrap_content"
        app:layout_height="wrap_content" />

    <Button
        app:id="@+id/button2"
        style="@style/ButtonBar"
        app:layout_width="150dp"
        app:layout_height="wrap_content"
        app:layout_below="@+id/button1"
        app:layout_centerHorizontal="true"
        app:layout_marginTop="65dp"
        app:text="@string/button2"
        app:typeface="sans" />

    <Button
        app:id="@+id/button3"
        style="@style/ButtonBar"
        app:layout_width="150dp"
        app:layout_height="wrap_content"
        app:layout_alignLeft="@+id/button1"
        app:layout_below="@+id/button2"
        app:layout_marginTop="65dp"
        app:text="@string/button3"
        app:typeface="sans" />

    <Button
        app:id="@+id/button1"
        style="@style/ButtonBar"
        app:layout_width="150dp"
        app:layout_height="wrap_content"
        app:layout_alignLeft="@+id/button2"
        app:layout_below="@+id/textView1"
        app:layout_marginTop="22dp"
        app:onClick="whenClicked"
        app:text="@string/button1"
        app:typeface="sans" />

    <TextView
        app:id="@+id/textView1"
        app:layout_width="wrap_content"
        app:layout_height="wrap_content"
        app:layout_alignParentTop="true"
        app:layout_centerHorizontal="true"
        app:layout_marginTop="39dp"
        app:paddingBottom="30sp"
        app:text="@string/title"
        app:textColor="@color/blue"
        app:textSize="60sp"
        app:textStyle="bold"
        app:typeface="sans" />

Android list ~

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="sehej.android.doge"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="sehej.android.doge.FullscreenActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

问题 View 的错误信息~

fullscreen_content_controls 无法解析或者不是字段 FullscreenActivity.java/???/src/sehej/android/doge 第 54 行 Java 问题

fullscreen_content 无法解析或者不是字段 FullscreenActivity.java/???/src/sehej/android/doge 第 55 行 Java 问题

~~~~??? is the project/application name
~~~~I have marked the section that received the errors with '***'s

最佳答案

你还没有定义

fullscreen_content_controls
fullscreen_content

上面的id在你的activity_main.xml这就是为什么你得到

fullscreen_content_controls cannot be resolved or is not a field FullscreenActivity.java .

查看您的代码时,您没有声明任何 View与 id

fullscreen_content_controls

fullscreen_content在你的activity_main.xml .

如果你想摆脱这个问题你必须定义两个Views使用您在代码中提到的 ID。

编辑

你通常会调用setContentView(int)使用定义 UI 的布局资源,并使用 findViewById(int)检索该 UI 中的小部件,因此无论您在 Ui Xml 中声明了什么 View ,您都可以获得它们。

就像在你的情况下你已经定义了按钮这样的东西

Button someButton = (Button) findViewById(R.id.button2);

现在将为您工作,您可以在您的应用程序中使用此小部件。

关于java - 错误依然存在~ "fullscreen_content_controls cannot be resolved or is not a field",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20878255/

相关文章:

java - 有没有比(1)…休息时更干净的方法?

java - 考虑在您的配置中定义 * 类型的 bean

javascript - 8 :00AM on specific date when the App got completely closed? 如何通知用户

android - 将 header 添加到 PreferenceActivity

android - 如何获取应用中的主要 Activity 名称?

java - 是否有一个图像设计社区可以与开发人员合作来创建具有更好、更优美的外观和感觉的应用程序?

java - 用字符数组中的一个字符替换两个字符

java - 范围搜索 3 列的字符串

java - 如何将接口(interface)的方法生成到所有实现类中?

android模拟器不断显示日志猫消息