2014-02-20 57 views
0

我遇到了編譯程序開始的問題,這是下面的代碼。在Android上編譯時發生錯誤:「R無法作爲變量解析」

我得到的錯誤是

"R cannot be resolved as a variable" line 12

"R cannot be resolved as a variable" line 18

package com.example.hangman_game_android; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); //line 12 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); //line 18 
     return true; 
    } 

} 

我的代碼的另一部分是...

<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=".MainActivity" > 

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

</RelativeLayout> 
+2

發佈您正在收到的錯誤...這非常有幫助。另外,請嘗試清理您的項目。最有可能的,有事要做[與此](http://stackoverflow.com/questions/2757107/developing-for-android-in-eclipse-r-java-not-generating) – codeMagic

+0

我剛剛添加了一些意見,以清除我的錯誤對不起。 – Cris

+1

我明白了。請參閱我在第一條評論中發佈的鏈接 – codeMagic

回答

0

由於codeMagic的建議,我將執行該項目的清潔這將解決缺失的參考文獻。

+0

歡迎來到SO!我意識到你不能評論,但這不是一個答案。而且由於已經被要求描述這個問題,所以可能沒有必要 – codeMagic