错误仍然存​​在〜" fullscreen_content_controls不能得到解决或不是场" [英] Error persists~ "fullscreen_content_controls cannot be resolved or is not a field"

查看:260
本文介绍了错误仍然存​​在〜" fullscreen_content_controls不能得到解决或不是场"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是怎样的一个小白Android开发者,我打了几个颠簸试图创建一个打开新布局的按钮。当我这样做,我得到了一些错误,不会消失,不管是我的尝试。对此,我复制大多数,我已经从原来的结构改变的xml文件和java文件,我将它们添加到一个新的项目,以为我所有的错误会消失。我真的需要一些帮助,我不能告诉你我一直被困在这个小错误多久。我重视的主要FullScreenActivity.java,activity_main.xml中,Android清单和错误消息。预先感谢您的帮助球员,我真的AP preciate吧! C:

FullScreenActivity.java〜

 包sehej.android.doge;
进口sehej.android.doge.util.SystemUiHider;
进口sehej.android.doge.R;
进口android.annotation.TargetApi;
进口android.app.Activity;
进口android.os.Build;
进口android.os.Bundle;
进口android.os.Handler;
进口android.view.MotionEvent;
进口android.view.View;公共类FullscreenActivity延伸活动{
    / **
     *系统UI是否应该被自动隐藏后,
     * {@link #AUTO_HIDE_DELAY_MILLIS}毫秒。
     * /
    私有静态最终布尔AUTO_HIDE = TRUE;    / **
     *如果{@link #AUTO_HIDE}设置,后等待的毫秒数
     *隐藏系统UI之前用户交互。
     * /
    私有静态最终诠释AUTO_HIDE_DELAY_MILLIS = 3000;    / **
     *如果设置,将切换相互作用时系统UI的知名度。除此以外,
     *将显示在交互系统UI的知名度。
     * /
    私有静态最终布尔TOGGLE_ON_CLICK = TRUE;    / **
     *这些标志传递给{@link SystemUiHider#的getInstance}。
     * /
    私有静态最终诠释HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;    / **
     *而{@link SystemUiHider}这项活动的实例。
     * /
    私人SystemUiHider mSystemUiHider;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);        的setContentView(R.layout.activity_main);    ****最后查看controlsView = findViewById(R.id.fullscreen_content_controls);
    ****最后查看内容查看= findViewById(R.id.fullscreen_content);        //设置SystemUiHider的实例来控制的系统UI
        //这个活动。
        mSystemUiHider = SystemUiHider.getInstance(这一点,内容查看,
                HIDER_FLAGS);
        mSystemUiHider.setup();
        mSystemUiHider
                .setOnVisibilityChangeListener(新SystemUiHider.OnVisibilityChangeListener(){
                    //缓存值。
                    INT mControlsHeight;
                    INT mShortAnimTime;                    @覆盖
                    @TargetApi(Build.VERSION_ codeS.HONEYCOMB_MR2)
                    公共无效onVisibilityChange(布尔可见){
                        如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.HONEYCOMB_MR2){
                            //如果ViewPropertyAnimator API可用
                            //(蜂窝MR2及更高版本),用它的动画
                            //在布局时的底部UI控件
                            //屏幕。
                            如果(mControlsHeight == 0){
                                mControlsHeight = controlsView.getHeight();
                            }
                            如果(mShortAnimTime == 0){
                                mShortAnimTime = getResources()。getInteger(
                                        android.R.integer.config_shortAnimTime);
                            }
                            controlsView
                                    .animate()
                                    .translationY(可见?0:mControlsHeight)
                                    .setDuration(mShortAnimTime);
                        }其他{
                            //如果ViewPropertyAnimator API不是
                            //可用,只是显示或隐藏在UI布局
                            //控制。
                            controlsView.setVisibility(可见?View.VISIBLE
                                    :View.GONE);
                        }                        如果(可见的放大器;&安培; AUTO_HIDE){
                            //安排一躲()。
                            delayedHide(AUTO_HIDE_DELAY_MILLIS);
                        }
                    }
                });        //设置用户交互手动显示或隐藏的系统UI。
        contentView.setOnClickListener(新View.OnClickListener(){
            @覆盖
            公共无效的onClick(查看视图){
                如果(TOGGLE_ON_CLICK){
                    mSystemUiHider.toggle();
                }其他{
                    mSystemUiHider.show();
                }
            }
        });
        };        //在与UI控件交互,任何推迟原定隐藏()
        //操作prevent控件的不和谐行为消失
        //而与UI交互。
    @覆盖
    保护无效onPostCreate(捆绑savedInstanceState){
        super.onPostCreate(savedInstanceState);        //触发初始隐藏()活动是不久后
        //创建的,简单地提示到UI控件的用户
        //可用。
        delayedHide(100);
    }    / **
     使用*触摸侦听器在布局UI控件延迟隐藏
     *系统UI。这是prevent的控制走开了不和谐的行为
     *当活动UI交互。
     * /
    View.OnTouchListener mDelayHideTouchListener =新View.OnTouchListener(){
        @覆盖
        公共布尔onTouch(查看视图,MotionEvent motionEvent){
            如果(AUTO_HIDE){
                delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
            返回false;
        }
    };    处理器mHideHandler =新的处理程序();
    可运行mHideRunnable =新的Runnable(){
        @覆盖
        公共无效的run(){
            mSystemUiHider.hide();
        }
    };    / **
     *时间表调用隐藏()在[延迟]毫秒,取消所有
     * previously预定电话。
     * /
    私人无效delayedHide(INT delayMillis){
        mHideHandler.removeCallbacks(mHideRunnable);
        mHideHandler.postDelayed(mHideRunnable,delayMillis);
    }
}

activity_main.xml中〜

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    的xmlns:程序=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:背景=@绘制/草
    机器人:paddingBottom会=@扪/ activity_vertical_margin
    机器人:paddingLeft =@扪/ activity_horizo​​ntal_margin
    机器人:paddingRight =@扪/ activity_horizo​​ntal_margin
    机器人:paddingTop =@扪/ activity_vertical_margin
    应用:填充=20SP
    应用:textAlignment =中心
    工具:上下文=MainActivity。>    < requestFocus的
        应用:layout_width =WRAP_CONTENT
        应用:layout_height =WRAP_CONTENT/>    <按钮
        应用:ID =@ + ID /按钮2
        风格=@风格/按钮栏
        应用:layout_width =150dp
        应用:layout_height =WRAP_CONTENT
        应用:layout_below =@ + ID /按钮1
        应用:layout_centerHorizo​​ntal =真
        应用:layout_marginTop =65dp
        应用:文本=@字符串/按钮2
        应用:字体=SANS/>    <按钮
        应用:ID =@ + ID /按钮3
        风格=@风格/按钮栏
        应用:layout_width =150dp
        应用:layout_height =WRAP_CONTENT
        应用:layout_alignLeft =@ + ID /按钮1
        应用:layout_below =@ + ID /按钮2
        应用:layout_marginTop =65dp
        应用:文本=@字符串/按钮3
        应用:字体=SANS/>    <按钮
        应用:ID =@ + ID /按钮1
        风格=@风格/按钮栏
        应用:layout_width =150dp
        应用:layout_height =WRAP_CONTENT
        应用:layout_alignLeft =@ + ID /按钮2
        应用:layout_below =@ + ID / textView1
        应用:layout_marginTop =22dp
        应用:的onClick =whenClicked
        应用:文本=@字符串/按钮1
        应用:字体=SANS/>    <的TextView
        应用:ID =@ + ID / textView1
        应用:layout_width =WRAP_CONTENT
        应用:layout_height =WRAP_CONTENT
        应用:layout_alignParentTop =真
        应用:layout_centerHorizo​​ntal =真
        应用:layout_marginTop =39dp
        应用:paddingBottom会=30sp
        应用:文本=@字符串/标题
        应用:文字颜色=@色/蓝
        应用:TEXTSIZE =60SP
        应用:文本样式=大胆
        应用:字体=SANS/>

Android清单〜

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=sehej.android.doge
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =18/>    <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=sehej.android.doge.FullscreenActivity
            机器人:configChanges =方向| keyboardHidden |屏幕尺寸
            机器人:标签=@字符串/ APP_NAME
            机器人:主题=@风格/ FullscreenTheme>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;
    < /用途>< /清单>

这是问题的错误信息〜

fullscreen_content_controls不能得到解决或不是一个领域FullscreenActivity.java / ??? / src目录/ sehej /安卓/总督
第54行的Java问题

fullscreen_content不能得到解决或不是一个领域FullscreenActivity.java / ??? / src目录/ sehej /安卓/总督
第55行的Java问题

  ~~~~?是项目/应用程序的名称
~~~~我标志着以'***的接收错误的部分


解决方案

您还没有定义

  fullscreen_content_controls
fullscreen_content

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


  

fullscreen_content_controls不能得到解决或不是现场FullscreenActivity.java。


由于看你的code你有没有用id声明任何查看

fullscreen_content_controls

fullscreen_content activity_main.xml中

如果你想摆脱这个问题,你必须定义两个查看与您在code都在提的ID。

修改

您通常会调用的setContentView(INT)与布局资源定义你的用户界面,并使用 findViewById(INT)检索在UI小部件所以,无论你认为在UI的Xml已经宣布你可以得到这些。

像你的情况已经定义按钮,所以像

 按钮someButton =(按钮)findViewById(R.id.button2);

会为你工作,现在你可以在你的应用程序中使用这个小工具。

I'm kind of a noob android developer, and I hit a few bumps while trying to create a button that opens a new layout. While I was doing that, I got a few errors that would not go away no matter what I tried. In response, I copied most of the xml files and java files that I had changed from the original structure, and I added them to a new project, thinking all my errors would go away. I really need some help, I can't tell you how long I have been stuck on this small error. I have attached the main FullScreenActivity.java, activity_main.xml, the Android Manifest, and the error messages. Thank you in advance for the help guys, I really do appreciate it! c:

FullScreenActivity.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 Manifest ~

<?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>

Error messages from problems view ~

fullscreen_content_controls cannot be resolved or is not a field FullscreenActivity.java /???/src/sehej/android/doge line 54 Java Problem

fullscreen_content cannot be resolved or is not a field FullscreenActivity.java /???/src/sehej/android/doge line 55 Java Problem

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

解决方案

You have not defined

fullscreen_content_controls
fullscreen_content

The above id in your activity_main.xml Thats why you are getting

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

As looking at your code you have not declare any View with the id

fullscreen_content_controls

fullscreen_content in your activity_main.xml.

If you want to get rid of this problem you have to define two Views with the id you are mentioning in your code.

Edit

you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI So whatever view you have declared in your Ui Xml you can get those.

Like in your case you have defined button so something like

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

will work for you now you can use this widget in your application.

这篇关于错误仍然存​​在〜&QUOT; fullscreen_content_controls不能得到解决或不是场&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆