2016-04-13 34 views
1

我遇到了我的代碼問題... 之前,它工作,然後我在佈局中添加了一些簡單的線條,現在我有很多erros。我試圖自己學習如何爲我的學校編寫一個應用程序,所以我不是專業人士。 感謝您的幫助。無法解析方法和LinearLayout

這裏的錯誤是 「無法解析R」

`@覆蓋 保護無效的onCreate(捆綁savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

majorOb = (Spinner) findViewById(R.id.spinnerMaj); 
    yearOb = (Spinner) findViewById(R.id.spinnerYear); 
    semesterOb = (Spinner) findViewById(R.id.spinnerSem); 
    classOB = (Spinner) findViewByID(R.id.spinnerClass); 
    button1 = (Button) findViewById(R.id.button1); 
    tv1 = (TextView) findViewById(R.id.textview1); 
    Resources res = getResources(); 
    array1 = res.getStringArray(R.array.Books);` 

這裏的錯誤是:元素的LinearLayout可是沒有所需的屬性:layout_height ADN layout_width

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
tools:context="com.example.marcosbiblio.projetofinal.MainActivity"> 
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"> 
+1

爲 「無法解析R」,清理並重建項目從構建選項 –

+1

可能重複[R無法解決 - Android錯誤](http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error) – Rovanion

回答

0

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
tools:context="com.example.marcosbiblio.projetofinal.MainActivity" 
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"></LinearLayout>