2012-11-03 131 views
0

我最近一直在試圖讓R.JAVA生成沒有用。我試過以下 1.添加空格清單文件 2.項目 - >清潔麻煩生成R.Java

所以我最後的猜測是,有我在XML文件中的一些錯誤I /月食一直沒能查看。所以我希望能有第二雙眼睛能夠檢查我的XML文件進行審查。只有三個,他們應該是非常基本的(我正在跟隨android書的介紹)。

清單文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.activites" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
    android:minSdkVersion="8" 
    android:targetSdkVersion="15" /> 

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

     <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".Activity2" 
     android:label="Activity 2" > 
     <intent-filter> 
     <action android:name="com.example.ACTIVITY2" /> 

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

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:text="@string/hello_world" 
    tools:context=".MainActivity" /> 

</RelativeLayout> 

Activity2.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="This is Activity 2!" /> 
</RelativeLayout> 

再次感謝所有的你,已經採取超時您忙碌的白天/黑夜的幫助像我這樣的初學者。此外,如果有任何建議,而不是在xml中的錯誤,請隨時提出。

如這裏請求是存在的問題出現在Windows的>顯示視圖 - >問題

  1. R 1不能被解析爲一個可變
  2. R 1不能被解析爲一個可變
  3. R 1不能被解析到一個變量

標記不是那麼明顯,它用來在catlog中用下面幾行代碼顯示調試信息。

public class MainActivity extends Activity { 

String tag =「Events」;

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.activity_main); 

    Log.d(tag, "In the onCreate() event"); 
} 
+1

當您嘗試構建時,您在控制檯中是否收到錯誤/警告? – Geobits

+1

在您的_Activity.xml_和_Activity2.xml_中,每個文件末尾都有一個? –

+0

@GabrielNetto他這樣做,它丟失了格式的帖子。 – Eric

回答

1

當我編譯代碼我得到以下錯誤:

資源\佈局\ Activity2.xml:無效的文件名:只能包含 [A-Z0-9_。]

所以解除資本A和重命名 「Activity2.xml」 到 「activity2.xml」

此外,如果這沒有幫助,試試這個: -

重命名你的包名其他。清潔。重新啓動Eclipse。將包重命名爲前一個。再次清潔。重新啓動Eclipse。

+0

是的,我很驚訝eclipse不會捕捉到這一點,通過擁有一個.xml文件有大寫字母時出現警告消息 –

+0

我實際上從Eclipse獲取了此消息。 我使用Eclipse 3.7.1靛藍我 – Doc

+1

,也還有我的意思說的是不是有錯誤出現在控制檯上,當有一個大寫字母創建一個XML警告消息出現。無論哪種方式,我學到了我的教訓,希望將來不會發生這種錯誤。 –

2

在Eclipse中可以檢查問題視圖(窗口 - >顯示視圖 - >問題)和/或控制檯視圖,以幫助在XML中有效地定位錯誤。如果您仍然需要幫助,您可能需要向我們發佈這些錯誤

+0

完成,問題只與java文件有關,而不是xml,所以我不知道這是否是問題,但我再次'是一個非常新的機器人。 –

0

tag應該是一個字符串變量。它被定義爲什麼?你可能應該在那裏對它進行硬編碼,除非你將它用作應用程序的全局變量。 http://developer.android.com/reference/android/util/Log.html#d%28java.lang.String,%20java.lang.String%29

編輯:R cannot be resolved - Android error有很多不同的答案,請嘗試閱讀這些答案。如果第一個解決不了你的問題,另一個可能。

+0

亞必須刪除我加回來的減速。它從問題列表中刪除標籤,但R.Java仍然不會生成 –

0

檢查您的進口。在那裏的任何地方是import android.R?如果是這樣,請將其移除。如果你真的在書中遵循一些android教程,並且它指示你使用Ctrl + shift + O或其他方式來組織或管理導入,那會導致它彈出。

+0

沒有android R不是任何類下的導入 –