2016-12-31 109 views
0

我是新的android開發與eclipse,當創建一個新的項目,我得到兩個錯誤。一個是src文件夾中,主要活動說:錯誤與R類和錯誤檢索父項目,Eclipse

「R不能解析爲一個變量」

而且也是在res文件夾,價值觀,styles.xml:

「C:\用戶\ userName \ workspace \ test \ res \ values \ styles.xml:7:錯誤:檢索項的父項時出錯:找不到與給定名稱'Theme.AppCompat.Light'匹配的資源。

我得到了同樣的錯誤3次,其中一次在values-v11中使用appcompat.light,另一次使用黑暗操作欄。我真的不知道該怎麼做。我覺得我好笨。甚至沒有能夠在我的手機中測試任何東西。

如果你能幫助我,我會非常感激。

下面是一些代碼:

package com.example.test; 

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

public class MainActivity extends Activity { 

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

,並在styles.xml

<resources> 

    <!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
    --> 
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level  can go here. --> 
</style> 

</resources> 

而且清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.test" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="21" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     </activity> 
    </application> 

    </manifest> 
+0

請使用Android Studio代替Eclipse。 Google不再支持使用Eclipse進行Android開發。 –

回答

2

首先,我會提供一些線索在原始問題上 您可能沒有正確添加appcompat庫。有一個答案here

第二件事是; Eclipse不再是Android開發所支持的IDE。您應該從Android開發人員網站下載Android Studio,在http://developer.android.com 在Android Studio中添加此庫並繼續工作要容易得多。

+0

其次是對Eclipse的警告 –

0

對我來說,這是一個「junit測試」包l的問題。幾周後,我發現我只需刪除「junit測試」軟件包,並從gradle文件中刪除它們。然後再次同步該項目,每件事情都很順利。您可以從「項目結構」設置的「應用程序」選項卡中刪除junit測試包。 我希望它也適用於你。