也許我的谷歌搜索技巧並不是最大的,但每當我谷歌這個問題,我只找到解決方案,當整個R文件不生成這不是我的問題。其他一切都很好,但是,R內沒有ID,所以我無法在XML中引用視圖。我已經嘗試過project-> clean,然後重新啓動adb服務器和eclipse,但都無濟於事。所有的幫助非常感謝。以下是我的代碼。R.java沒有在Android中生成R.id
public class MainMenu extends Activity {
/*
* Class member variables
*/
private Button mMicrophoneButton;
private ListView mMessageList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu_layout);
setWidgets();
}
private void setWidgets() {
this.mMicrophoneButton = (Button) findViewById(R.id.bMicrophone);
}
}
下面是我的XML,這裏有很多新的東西,我不承認我已經完成的以前的項目。但我沒有發現任何錯誤,這是我所知道的是,通常像這樣的問題,第一個原因。:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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=".MainMenu"
tools:ignore="HardcodedText" >
<ScrollView
android:id="@+id/svMessageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="9" >
<TextView
android:id="@+id/tvTest"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="test" />
</ScrollView>
<Button
android:id="@+id/bMicrophone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:minHeight="30dp"
android:text="Speak Now" />
</LinearLayout>
可能是你輸入了錯誤的R – Blackbelt 2013-03-13 15:10:47
這是我工作區中唯一的R.我明白你的意思,但我不認爲是這樣。特別是因爲我從來不需要在我的其他android項目中的活動中顯式導入R. Eclipse僅以紅色標出「R.id.bMicrophone」中的「id」。我檢查了R,除了id嵌套類之外,所有內容都在那裏。 – marchese29 2013-03-13 15:15:18
我不知道你在這裏是什麼意思,這是一件新事物嗎?我必須使用R的實際導入語句嗎? Eclipse在MainMenu.java中使用它時會識別R,所以我認爲我不需要。特別是因爲我從來沒有過。 – marchese29 2013-03-13 15:18:00