42702

Error persists~ “fullscreen_content_controls cannot be resolved or is not a field”

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

Answer1:

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.

<strong>Edit</strong>

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.

Answer2:

This is what I did to solve this problem I faced. It happens when you press ctrl+shift+O to auto import. the solution is to Replace import android.R with .R in your activity java file.

Recommend

  • How to make a UIImageView centered in a Scrollview when zoom out?
  • Table View load more cell?
  • Disable Xamarin Form and Show Activity Indicator
  • Custom UITableview Cell Occasionally Overlapping/Reproducing On Top Of Other Cell
  • iOS - Can I disable accessibility on cell.textLabel.text?
  • How to acces variable in arrayadapter getView from onItemClick
  • Toggle button in a list view loose their state when scrolled of screen in Android
  • HoloEverywhere SeekBar ClassCastException
  • how to passing listview images passing another activity [closed]
  • Show progress of seekbar in a textview inside a custom alert dialog
  • Select Address from MapActivity and return back to MainActivity
  • Android Floating Window
  • What other Adapters can I use for ListView?
  • Populatate the spinner from Firebase database
  • Android Media player seekbar play from stopped position
  • Android how to set a transparent image resource of a view? or Remove the image?
  • RxJava,Retrofit Error :Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
  • Update Search Results to Lazy Adapter in android
  • Why does .addView throw this parent/child exception?
  • Eventbus onMessageEvent not getting called
  • How to Handle Click on Imageview in Custom Listview with image and Textview?
  • Android: How do you create an EditText field in java class
  • CloseOptionsMenu doesn't work?
  • Unable to resolve Static method?
  • matlab crashes without dump file when using fopen for file
  • Prevent page break in text block with iText, XMLWorker
  • Python 3.2.2, error(scripts to exe)
  • NSIS decompiler
  • Problem while Building a Setup Project for a windows Service?
  • QLineEdit password safety
  • Nant, Vault & Windows Integrated Authentication
  • Bug in WPF DataGrid
  • Adding custom controls to a full screen movie
  • jQuery tmpl and DataLink beta
  • How can I estimate amount of memory left with calling System.gc()?
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • How to stop GridView from loading again when I press back button?
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory