2014-08-28 77 views
0

我是Android編程的新手,並且即將運行Android應用程序。 我得到了R.layout無法解析爲變量錯誤。當我導入com.package.r;並刪除了android.r它沒有做任何事情。在清理項目後錯誤消失了,但是它在r.layout.activity_main上發生了錯誤(轉換爲activity_list ...)。該代碼片段已附加。在R類型中創建字段佈局/ main - 無法解析

import android.app.Activity; 
import android.content.pm.ActivityInfo; 
import android.os.Bundle; 
import android.view.Menu; 
import com.procedure.culture.R; 


public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
} 

@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);` 

我已重新啓動eclipse並清理了一百萬次項目,但徒勞無功。 activity_main.xml中的所有內容都已被評論。但錯誤仍然存​​在。請幫助。

<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" 
android:background="#A1F5F8" > 

<!-- 
<TextView 
    android:id="@+id/tv_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/title" 
    android:textColor="#000000" 
    android:textSize="30dp" 
    /> 
    --> 
+0

您關閉了標記嗎? – Robert 2014-08-28 11:58:30

+0

是@Robert,多數民衆贊成在關閉! – CSA 2014-08-28 12:02:59

+0

檢查:http://www.tutorialspoint.com/android/android_hello_world_example.htm – 2014-08-28 12:03:40

回答

1

嘗試以下操作:

1.check whether there are bugs in XML files. 

2.Try to rebulid your application 

3.Check for any missing library files. 
從你的問題

也不要導入[R包。它的自動生成文件。刪除所有關於r的輸入。

可能是您的XML文件中存在一些錯誤。檢查..

+0

檢查錯誤。沒有在XML中。重建也完成了。沒有幫助。 :( – CSA 2014-08-28 12:04:20

+0

如何檢查lib文件? – CSA 2014-08-28 12:06:54

+0

右鍵項目,轉到屬性 – Subburaj 2014-08-28 12:07:51

0

有時清洗多次android失去對R的引用(例如R.id ...) 也避免運行其他方的應用程序並在您創建的應用程序中複製代碼。

避免清單文件setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),而不是設置方向:

<activity 
    android:name=".activity.MainActivity" 
    android:label="@string/app_name" 
    android:screenOrientation="portrait" 
    android:configChanges="orientation"> 
0

雖然我正在尋找R上的錯誤,我讀的地方取消選中Java的生成器。我這樣做,但它給了我在這個問題線程中的錯誤。所以現在當我檢查Java構建器時,錯誤已經消失。另外,我試圖在錯誤開始彈出時在xml中添加imageview。我評論過它,但沒有發生任何事情。現在,當錯誤消失後,我對它進行了評論,但在應用程序中無法看到圖像。 無論如何,感謝您的幫助! :)

+0

這是類型R已經定義錯誤 http://stackoverflow.com/questions/5283414/type-r-is -already定義的誤差 – CSA 2014-08-28 12:26:29

相關問題