0

Maybe my Googling skills aren't the greatest, but whenever I Google this problem, I only find solutions to when the whole R file isn't generated which isn't my problem. Everything else is generating just fine, however, there is no ID within R, so I have no way of referencing the views in my XML. I've already tried project->clean, and restarting the adb server and eclipse, neither to any avail. All help is greatly appreciated. Below is my code.

public class MainMenu extends Activity {

    /*
     * Class member variables
     */
    private Button mMicrophoneButton;
    private ListView mMessageList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_menu_layout);
        setWidgets();
    }

    private void setWidgets() {
        this.mMicrophoneButton = (Button) findViewById(R.id.bMicrophone);
    }

}

Below is my XML, there's a lot of new stuff here that I don't recognize from previous projects I've done. But I'm not finding any mistakes, which I know is usually the first cause of problems like this.:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainMenu"
    tools:ignore="HardcodedText" >

    <ScrollView
        android:id="@+id/svMessageView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="9" >

        <TextView
            android:id="@+id/tvTest"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="test" />

    </ScrollView>

    <Button
        android:id="@+id/bMicrophone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:minHeight="30dp"
        android:text="Speak Now" />

</LinearLayout>
4

3 回答 3

4
  • Make sure all of your files under res are building properly. Even if your R file is already generated it won't update if you have any errors.
  • If you're referencing any library projects then you may have issues if there are any errors in that library project (src or res).
  • In eclipse do a Project-->Clean on your project and all library projects it references.
  • Delete gen folder and let eclipse auto generate it.
于 2013-03-13T15:16:40.753 回答
0

you need to save the xml file before cleaning the project for the ids to show up in R.java

于 2014-08-19T21:52:42.663 回答
0

I have Got the Same error but I got it solved by cleaning and rebuilding the project.

Actually, we can add Id there manually as well. I have done that couple of times.

But you can solve it by following the steps below

  • Open the Android Studio
  • Go to the Build
  • Then Clean project
  • after that Rebuild project

It will work definitely.

于 2017-11-23T12:12:30.747 回答