2

数か月前に正しく機能していた古いプロジェクトを開きました。今、私はほとんどすべてのアクティビティでバグまたはエラーに関連する何かを食しました - R cannot be resolved to a variable.

ここに画像の説明を入力

スタックオーバーフローで読み取ったすべてのアクションを実行しましたが、まだ何も機能していません:

  • インポートチェック済み
  • プロジェクトの清掃

ここに画像の説明を入力

問題は XML ファイルの 1 つにある可能性があると思います。このファイルには、次のような 3 つのエラーも含まれています。No resource identifier found for attribute "atribute" in package my.package

このアクティビティでは、Facebook のサンプルを使用してコンテンツを共有しています。コード:

<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright 2010-present Facebook.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:facebook="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#FFF"
        >
    <LinearLayout android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:background="#FFF"
                  android:id="@+id/activity_share_ui_container">
        <com.facebook.widget.LoginButton   <!-- 2 errors here --->
                android:id="@+id/login_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                facebook:confirm_logout="false"
                facebook:fetch_user_info="true"
                />
        <LinearLayout
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="center_horizontal"
                android:orientation="vertical">
            <TextView
                    android:id="@+id/greeting"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_gravity="center"
                    android:textColor="#333"
                    android:textSize="18sp"/>
            <com.facebook.widget.ProfilePictureView <!-- 1 error here --->
                    android:id="@+id/profilePicture"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:gravity="center_horizontal"
                    android:layout_marginBottom="10dp"
                    facebook:preset_size="normal"/>
            <Button
                    android:id="@+id/postStatusUpdateButton"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Post Status Update"
                    />
            <Button
                    android:id="@+id/postPhotoButton"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Post Photo"
                    />
            <Button
                    android:id="@+id/pickFriendsButton"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Pick Some Friends"
                    />
            <Button
                    android:id="@+id/pickPlaceButton"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Pick Place"
                    />
        </LinearLayout>
    </LinearLayout>
    <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>

</LinearLayout>

プロパティに問題があります: ここに画像の説明を入力

私は何を逃したのですか?

4

4 に答える 4

4

xml ファイルで facebook UI 要素を使用しました。Android プロジェクトは、FaceBook SDK の参照を削除または移動した可能性があるため、参照を取得できないようです。次の方法で確認できます。

Project Explorer からプロジェクトを右クリック --> [プロパティ] を選択 --> [Android] を選択 --> FaceBook SDK の参照が正しいかどうかを確認します。

正しい参照を提供すると...ビルドエラーは、クリーンおよびビルド後に消えます。

于 2013-09-09T13:45:35.663 に答える
2

回答が与えられているため、これはエラーが発生している理由を明確にするためだけのものです:

R ファイルは、すべてのリソースがコンパイルされている場合にのみ生成できます。お気づきのとおり、リソースにエラーがあり (おそらく FB SDK の適切なインクルードに関連しています)、R.java ファイルの生成が妨げられています。ファイルが存在しないため、解決できませんR cannot be resolved to a variable

Eclipse は、同様の名前のクラス (android.R) をインポートするか、R という名前の何か (クラス、列挙型、変数など) を作成することを提案しますが、これらのソリューションはいずれも、この場合に必要なものではありません。

あなたが提供したスクリーンショットから、FB SDK のインポートに何か問題があります。[削除] を選択し、もう一度追加します。

于 2013-09-09T13:54:42.237 に答える