简体   繁体   English

R-ANDROID问题

[英]problems with R - ANDROID

when i create a layout called " main.xml ": 当我创建一个名为“ main.xml”的布局时:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/button"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/button" />

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />
</LinearLayout>

when i go to the main to create a button " button = (Button) findViewById(R.id.button); " i have an error , i cant find the button in R.id and same for the spinner the id dont exist in R.id 当我去主要创建一个按钮时,“ button =(Button)findViewById(R.id.button);”我遇到一个错误,我在R.id中找不到该按钮,并且对于微调框,id在其中不存在R.id

help me plz 请帮我

You're probably importing the wrong version of R. There are two versions which exist: the static R class which exists in android.R and then there is also yourPackageName.R. 您可能导入了错误的R版本。存在两个版本:存在于android.R中的静态R类,然后还有yourPackageName.R。 If you import the former none of your Ids will be found. 如果导入前者,则不会找到您的ID。

Make sure you don't have any files, pictures, etc in your drawable or assets folder with capital letters, spaces, or dashes. 确保在drawable或assets文件夹中没有大写字母,空格或破折号的文件,图片等。 Just use plane old lowercase. 只需使用旧的小写字母即可。 Also, try to clean your project. 另外,尝试清理您的项目。 Go to project > clean. 转到项目>清理。 Then restart eclipse. 然后重新启动Eclipse。 Hope this helps. 希望这可以帮助。 Also eclipse won't reconize any changes in XML files without saving first. 另外,如果不先保存,eclipse不会协调XML文件中的任何更改。 Make sure to save after you add a button, ect. 添加按钮后,请确保保存。

尝试验证XML文件中没有错误,而不是尝试清理项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM