Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5996633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:07:51+00:00 2026-05-23T00:07:51+00:00

I am trying to code some basic stuff (listView and the like) in Android.

  • 0

I am trying to code some basic stuff (listView and the like) in Android. My problem is as follows:
1. Any resource that I write (eg. an xml file specifying the content of a listView or a button), gets registered in the R class but eclipse flags it as an error when I try to use it.

Example:

Relative Layout xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <ListView android:id="@android:id/android:list"
     android:textFilterEnabled="true"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:dividerHeight="3dp"
  />

  <TextView android:id="@+id/simpleText"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>

  <Button android:id="@+id/nextButton"
     android:text="@string/next"
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:layout_alignParentBottom="true"
     android:layout_centerHorizontal="true"
     android:layout_centerVertical="true"
  />

</RelativeLayout>  

Code is as follows:

public class sample extends ListActivity {
    /** Called when the activity is first created. */

    private Button nxtButton;

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

        Log.v(this.toString(), "Inside the function.");

        nxtButton = (Button)findViewById(R.id.nextButton);
        nxtButton.setOnClickListener(new View.OnClickListener() {   
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //This method is to change to the next screen.
                Log.v(this.toString(), "The next button has been clicked. Taking you to the next screen.");             
            }
        });

        }
}  

R.java looks like so:

public final class R {
    public static final class attr {
    }
    public static final class drawable {
        public static final int icon=0x7f020000;
    }
    public static final class id {
        public static final int nextButton=0x7f050001;
        public static final int simpleText=0x7f050000;
    }
    public static final class layout {
        public static final int relLayout=0x7f030000;
        public static final int list_item=0x7f030001;
        public static final int main=0x7f030002;
    }
    public static final class string {
        public static final int app_name=0x7f040001;
        public static final int hello=0x7f040000;
        public static final int nextButton=0x7f040002;
    }
}  

My problem is as follows:
1. Even though the next button is registered in R.java, I get an error every time I try to do a findViewById on any resource that I have defined. Building the project also does not yield any results.

The error I get is: nextButton cannot be resolved or is not a field

I have come across a few questions on SO on these lines, but none whose solutions I have been able to use successfully.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:07:52+00:00Added an answer on May 23, 2026 at 12:07 am

    You should ensure you’ve imported your R java class, not android.R.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to write some code that would check if an item has
I'm trying what, to me, seems like some fairly basic code contracts code. I've
I'm trying to convert some code that worked great in VB, but I can't
I'm trying to get some code working that a previous developer has written. Yep,
I'm trying to write some code to find a specific XmlNode object based on
I'm trying to write some code to work with an htdigest password file. The
I'm trying to write some code which replaces old content with a placeholder while
I'm trying to create a Tile rendering program. Heres some basic code. Header class
I'm very new to ruby and trying some basic stuff. When I send HTTP
I am trying to access some basic info from an XML based API. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.