2016-01-15 35 views
0
<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" 
      android:background="@drawable/background1" 
      tools:context="com.example.flavours.Category" > 

     <ImageView 
       android:id="@+id/homeimage" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerVertical="true" 
       android:layout_centerInParent="true" 
       android:src="@drawable/ice1"/> 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_centerHorizontal="true" 
       android:layout_marginBottom="25dp" 
       android:text="Medium Text" 
       android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </RelativeLayout> 

每次我在更改構建目標(6.0)到(5.0.1)後都沒有生成R(R.id/layout)問題時。 我已經多次清理了該項目,並且當我立即清理了我的項目時,出現了「r」錯誤(R無法解析爲變量)。我還導入了我的(com.example.flavours.R;),但刪除了whn我按下Ctrl + shift + o。新的xml佈局文件沒有被添加到R.java

+0

檢查所有內容的資源文件夾,例如(可繪製的,值和佈局)等。 –

+0

我只有在我的項目中有一個錯誤時纔會遇到這種情況,它會阻止生成R.java;通常是由aapt工具報告的錯誤。這可能是無效的XML或文件名或res /目錄中的其他錯誤。檢查aapt的輸出以查看錯誤是什麼。 – dsh

回答

0

我檢查了你的代碼,我測試了它, 它的真實和作品!

確保你的新的.xml文件,有一個有效的名稱
有效的名稱只包含

  1. 小寫字母'az`
  2. 號`0-9`他們should`nt是在文件名的第一個。
  3. 下劃線`_`

對項目和清理源也右鍵

Right Click On Project > Source > Clean Up... 

或檢查構建路徑不需要的變化

Right Click On Project > Build Path > Configure Build Path...