2014-02-27 21 views
1

我剛剛創建了一個新的活動(project-> new-> android activity),並且在R文件不能識別活動創建的佈局時出現錯誤。我用Ubuntu的13.10(64位)爲什麼當我創建一個新的活動時,「setContentView」無法識別我的佈局?

public class OrderKaraokeActivity extends SherlockActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_order_karaoke); 
    } 
} 

activity_order_karaoke:

<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:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".OrderKaraokeActivity" > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/hello_world" /> 

</RelativeLayout> 

enter image description here

控制檯: 描述資源路徑位置類型 activity_order_karaoke不能得到解決或不是一個場OrderKaraokeActivity .java/src/com/example/adicionalesprueba line 18 Java問題

導入:

enter image description here

控制檯問題:

enter image description here

+1

你能給我們佈局文件的名字嗎? – Tomas

+0

您的佈局文件是否正確命名並放置在'res/layout'中? – Joffrey

+2

錯誤具體提及什麼?也許你生成的R文件沒有建立 – rperryng

回答

6

刪除以下

import com.twable.R; 
import com.twable.R.layout; 
import com.twable.R.menu; 

,包括import com.example.adicionalesprueba.R

----

檢查包瀏覽器(日食的左側窗格中),打開項目的gen文件夾,打開項目的包裝,你應該看到一個R.java文件。如果你沒有,你是R文件沒有被生成。嘗試清理您的項目,Project --> Clean。如果該文件仍然不存在,那麼您的文件不是正在構建的R。這可能發生的原因很多。一個非常常見的是,你的XML文件中的一個不正確的結構

enter image description here

+0

'無法解析導入com.example.adicionalesprueba.R'和'R無法解析爲變量' – cheloncio

+1

奇怪。刪除我在評論中提到的所有導入語句,點擊'CTRL + SHIFT + O',你會看到一個與你的包相匹配的建議。 – rperryng

+0

不工作,問題是佈局... R類不重新佈局...這是錯誤139在ubuntu = /我不知道如何修復它 – cheloncio

1

檢查進口。刪除如果在那裏生成,則導入android.R

相關問題