2012-06-04 70 views
1

我爲一個活動編寫簡單的android代碼,並在佈局文件夾中通過名爲second.xml的xml文件提供了它的視圖。我在mainfiest文件中提到了這個活動。但是我面對setContentView方法中的「秒不能解決或它不是字段」的錯誤。 請給予解決我無法解析或不是字段

import android.R; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class Second extends Activity 
{ 
    ImageView imageView; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.second); 

     // Intent i=getIntent(); 
    } 
} 
+6

,你應該修改的問題,並把代碼與問題 – Lucifer

回答

2

你只需要從工程 - >清潔清理項目,也刪除進口android.R;清理它之前,確保您有src/layout/second.xml下的second.xml文件。

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class Second extends Activity 
{ 
    ImageView imageView; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.second); 

    //  Intent i=getIntent(); 
    } 
} 
+0

感謝Imaran..it工作你做了什麼 –

+1

錯:您導入了錯誤的R類。您應該始終將您的解決方案中生成的R類放入您的導入中,而不是android.R。我希望這能澄清究竟發生了什麼錯誤,所以不會再發生。 – Wottah

+0

你的答案是正確的伊姆蘭,它的工作..謝謝 –

0

請刪除此行進口

import android.R; 

再用乾淨的就像這樣:

轉到工程>>清潔項目。我想你可能會解決你的問題; 查看更多詳情:R can not resolve

0

刪除import android.R;並清理您的項目。只有當您嘗試使用Android提供的數據時,才應該導入android.R。例如,爲了顯示與單排列表視圖,你會使用Android提供的佈局和TextView的如下:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
    android.R.layout.simple_list_item_1, android.R.id.text1, values);