2

私はここ数週間、elcipseを使用しています。コードは正常に機能しましたが、突然機能しなくなりました。このエラーが発生します、

main.xml:有効なレイアウト参照を指定する必要があります。レイアウトID@layout/requiredが無効です。

私のXMLコード

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


    <!--  select between BIN or auction -->
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

    <Button
        android:id="@+id/AuctionButton"
        android:layout_marginLeft="82dp"
        android:layout_width="119dp"
        android:layout_height="wrap_content"
        android:onClick="showAuctionOptions"
        android:text="Auction" />


    <Button
        android:id="@+id/BINButton"
        android:layout_marginLeft="-2dp"
        android:layout_width="119dp"
        android:layout_height="wrap_content"
        android:onClick="showAuctionOptions"
        android:text="Buy it now" />

    </LinearLayout>

        <include android:id="@+id/cell1" layout="@layout/required"/>

        <include android:id="@+id/cell2"  layout="@layout/gray_line" />

        <!--**  Show if Buy it now is selected **-->
        <include android:id="@+id/cell3" layout="@layout/buyitnow" />
        <!-- ** End Buy it now display ** -->

        <!--** Show if auction selected ** -->
        <include android:id="@+id/cell4" layout="@layout/auction" />

        <include android:id="@+id/cell5"  layout="@layout/gray_line" />

        <include android:id="@+id/cell6" layout="@layout/addons" />

        <include android:id="@+id/cell7" layout="@layout/calculate" />      

</LinearLayout>

</ScrollView>

エラーは最初のインクルードで発生しますが、それを削除すると、2番目のインクルードでエラーが発生します。すべてのインクルードを削除すると、Javaコード内で「Rを解決できませんでした」というエラーが発生します。

私が試したこと、

  • プロジェクトの清掃
  • 日食を再開する
  • コンピューターを再起動する

これは私のAndroidManifestXMLファイルです。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="toggler.state"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name">
        <activity
            android:name=".TogglerActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

どれもうまくいきませんでした。誰か助けてもらえますか?

ありがとう

4

2 に答える 2

3

エラーは、レイアウトの別の場所で発生した可能性があります。余分な2つを削除しますxmlns:android="http://schemas.android.com/apk/res/android"

xmlns名前空間を定義するために使用されます。ほとんどの場合、最上位の要素のみがそれを持つことができます。

XML の "xmlns" とはどういう意味ですか? をご覧ください。誰かがxmlns説明について読みたい場合。

また、XML ファイルがすべて小文字であることを確認してください。

また、マニフェストで正しいパッケージが指定されているかどうかも確認してください。https://stackoverflow.com/a/7496766/935779から取得

チェックインする価値がありAndroidManifest.xmlます。属性パッケージに正しい値があります。

あれは、<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.correct.package.name" ...

それを変更すると、R.java が再生成されます。

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


    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <!--  select between BIN or auction -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:orientation="horizontal" >

        <Button
            android:id="@+id/AuctionButton"
            android:layout_marginLeft="82dp"
            android:layout_width="119dp"
            android:layout_height="wrap_content"
            android:onClick="showAuctionOptions"
            android:text="Auction" />


        <Button
            android:id="@+id/BINButton"
            android:layout_marginLeft="-2dp"
            android:layout_width="119dp"
            android:layout_height="wrap_content"
            android:onClick="showAuctionOptions"
            android:text="Buy it now" />

        </LinearLayout>

        <include android:id="@+id/cell1" layout="@layout/required"/>

        <include android:id="@+id/cell2"  layout="@layout/gray_line" />

        <!--**  Show if Buy it now is selected **-->
        <include android:id="@+id/cell3" layout="@layout/buyitnow" />
        <!-- ** End Buy it now display ** -->

        <!--** Show if auction selected ** -->
        <include android:id="@+id/cell4" layout="@layout/auction" />

        <include android:id="@+id/cell5"  layout="@layout/gray_line" />

        <include android:id="@+id/cell6" layout="@layout/addons" />

        <include android:id="@+id/cell7" layout="@layout/calculate" />      

    </LinearLayout>

</ScrollView>
于 2012-07-05T15:26:59.653 に答える
0

同様の問題があり、インクルードタグに layout_width と layout_height を指定することで修正できました。

于 2013-07-12T01:32:12.390 に答える