R.java没有生成

时间:2014-04-27 13:53:28

标签: android eclipse android-layout r.java-file

我一直在尝试这一天,在stackoverflow上尝试所有给定的解决方案。最后的希望是在我的xml文件中找到一个错误(对应于活动),我无法检测到。所以我在这里包含了所有XML文件,请告诉我某处是否有错误?

main.xml(对应Main.java)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:background="@drawable/android_bck"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/result"
        style="@style/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to App!" >
    </TextView>

    <Button
        android:id="@+id/connectBtn"
        style="@style/layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dip"
        android:layout_marginRight="50dip"
        android:text="Connect" >
    </Button>

    <Button
        android:id="@+id/disconnectBtn"
        style="@style/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="50dip"
        android:layout_marginRight="50dip"
        android:text="Disconnect" >
    </Button>

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

    <ListView
        android:id="@+id/pairedDeviceList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:scrollbarFadeDuration="60"
        android:scrollbarStyle="outsideInset"
        android:scrollbarThumbVertical="@drawable/icon2"
        android:scrollbars="vertical" >
    </ListView>

    <ImageView
        android:id="@+id/logo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginLeft="35dip"
        android:layout_marginRight="35dip"
        android:layout_marginTop="100dip"
        android:background="@drawable/icon2" >
    </ImageView>

</LinearLayout>

controls.xml(对应于Controls.java)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/neon"
    android:baselineAligned="false"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="T1" >
        </Button>

        <Button
            android:id="@+id/button5"
            style="@style/layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="T5" >
        </Button>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left" >

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="T2" >
        </Button>

        <Button
            android:id="@+id/button6"
            style="@style/layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="T6" >
        </Button>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left" >

        <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="T3" >
        </Button>

        <Button
            android:id="@+id/button7"
            style="@style/layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="T7" >
        </Button>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left" >

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="T4" >
        </Button>

        <Button
            android:id="@+id/button8"
            style="@style/layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="T8" >
        </Button>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="left" >

        <TextView
            android:id="@+id/textView1"
            style="@style/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="Fan 1" >
        </TextView>

        <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="100dip"
            android:layout_marginRight="20dip" >
        </SeekBar>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView2"
            style="@style/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="Fan 2" >
        </TextView>

        <SeekBar
            android:id="@+id/seekBar2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="100dip"
            android:layout_marginRight="20dip" >
        </SeekBar>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/textView3"
            style="@style/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:text="Fan 3" >
        </TextView>

        <SeekBar
            android:id="@+id/seekBar3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="100dip"
            android:layout_marginRight="20dip" >
        </SeekBar>
    </RelativeLayout>

</LinearLayout>

这是我在按钮的样式属性上应用的res / values中的“styles.xml”:

<?xml version="1.0" encoding="utf-8"?> 
<resources>
<style name="text">
    <item name="android:padding">4dip</item>
    <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
    <item name="android:textColor">#FFFFFF</item>

</style>

<style name="layout">
<item name="android:padding">4dip</item>
    <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
    <item name="android:background">#C0C0C0</item> 
    <item name="android:textColor">#FFFFFF</item>
    <!--for transparent background> -->

</style>
</resources>

2 个答案:

答案 0 :(得分:0)

如果您的项目中没有错误,请尝试清理它。 项目菜单 - &gt;清洁

或删除R.java文件

还尝试使用android lint显示所有警告,尝试修复它。

enter image description here

答案 1 :(得分:0)

我尝试修改style.xml文件,我使用了以下文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

    <style name="textt">
        <item name="android:padding">4dip</item>
        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
        <item name="android:textColor">#FFFFFF</item>
    </style>

    <style name="layoutt">
        <item name="android:padding">4dip</item>
        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
        <item name="android:background">#C0C0C0</item>
        <item name="android:textColor">#FFFFFF</item>
        <!-- for transparent background> -->

    </style>

</resources>

并使用其他xml文件中指定的给定名称生成缺少的图标和背景,结果是为我生成了R.java。所以我认为你的问题可以通过style.xml

相关问题