2015-09-06 156 views
1

我最近決定將我的工作環境從Eclipse 更改爲Android Studio。我決定通過Android Studio導入我的Eclipse項目。Android Studio找不到現有的符號

問題是,當我編譯我的代碼時,遇到2個錯誤,它說它找不到兩個現有的符號。這些符號實際上是保存在res <可繪製的< hdpi中的兩個png圖片。但是,程序仍然無法找到這兩張照片。我有一堆其他圖片可以在同一個文件夾中完美地工作。我通過刪除導致錯誤的兩張圖片控制了這一點,並以成功的結果測試了應用程序。

這裏是整個錯誤消息:

(1)

Error:(101, 32) error: cannot find symbol variable thegodfather 
Error:(101, 78) error: cannot find symbol variable kingofcomedy 
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
Error:Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

(2)

/Users/rawandsultani/Documents/ANDROID/V1/v11/app/src/main/java/com/exple/top100/Top100Activity.java:101: error: cannot find symbol 
      flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy, 
             ^
    symbol: variable thegodfather 
    location: class drawable 
/Users/rawandsultani/Documents/ANDROID/V1/v11/app/src/main/java/com/exple/top100/Top100Activity.java:101: error: cannot find symbol 
      flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy, 
                        ^
    symbol: variable kingofcomedy 
    location: class drawable 
Note: Some input files use or override a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
2 errors 

FAILED 

FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task ':app:compileDebugJavaWithJavac'. 
> Compilation failed; see the compiler error output for details. 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

(3)

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0. 
     Searched in the following locations: 
     file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom 
     file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.jar 
     https://jcenter.bintray.com/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom 
     https://jcenter.bintray.com/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.jar 
     Required by: 
     :v11:unspecified 
     Consult IDE log for more details (Help | Show Log) 

的圖像保存在一個數組,這裏是數組:

flag = new int[] {R.drawable.thegodfather,R.drawable.thegeneral,R.drawable.kingofcomedy, 
        R.drawable.drstrangelove} 

兩個不工作的R.drawables是.godfather和.kingofcomedy。

我檢查了資源確實存在,甚至刪除並替換它們,沒有任何運氣。

我環顧四周堆棧來尋找答案,發現了很多類似的問題,但這些人的被清洗或者項目,無效並重新啓動或重建,甚至重新啓動該程序解決。這些都沒有爲我工作。

這裏是我的gradle.build代碼:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 


    defaultConfig { 
     applicationId "com.exple.v1" 
     minSdkVersion 15 
     targetSdkVersion 23 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
     } 
    } 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_7 
     targetCompatibility JavaVersion.VERSION_1_7 
    } 
} 

dependencies { 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile fileTree(dir: 'libs', include: ['*.jar']) 

} 

這裏是我的清單文件,以防萬一有人開始需要看看它:

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

    <uses-sdk 
     android:minSdkVersion="15" 
     android:targetSdkVersion="23" /> 

    <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" 
      android:screenOrientation="portrait"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

環顧四周後有點,我想我已經找到了我的problem,但我不確定在哪裏實施解決方案代碼,如果您點擊鏈接,鏈接位於鏈接中。它是上限還是下限?

+0

你確定你已經下載了構建工具和最新版本的android sdk嗎? –

+0

是的,我確定,我已經下載了幾乎所有的東西。 – Rawand

回答

0

這是你的問題之一。我不知道它是否會解決其他問題。

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0. 

這個版本不存在

檢查您的頂級build.gradle。您應該使用版本1.3.0而不是23.0.0。

buildscript { 
    repositories { 
     jcenter() 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:1.3.0' 
    } 
} 

這是Android的gradle插件,它與sdk無關。

+0

我正在顯示的gradle.build是較低的級別,但是我檢查了較高級別並且它是正確的,就像您已經顯示的那樣 – Rawand

0

您的問題不在於資源。問題是,你的構建工具無法找到:

Gradle sync failed: Could not find com.android.tools.build:gradle:23.0.0. 

生成您的資源文件(包含所有資源的ID)所需的工具無法找到,這意味着永遠不會產生你R類,並因此Java編譯器抱怨找不到這些符號。

您已經表明您擁有所有最新的Android SDK更新,但您確定Android Studio指向正確的Android SDK位置嗎? 假設你使用的是Android SDK的一些實例 - 但Android Studio自帶了它自己的Android SDK實例,可能不會使用你認爲的那個。

有錯誤看看路徑:

Searched in the following locations: 
     file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/23.0.0/gradle-23.0.0.pom 

這是否路徑您的計算機上存在嗎?它是在哪裏安裝您的Android SDK?你能找到那個地方的23.0.1構建工具文件夾嗎?如果沒有,你可能需要解決這個問題來解決你的問題 - this question可能會幫助你。

+0

您突出顯示的錯誤不再接收。因此,我假定SDK路徑是有序的。我已經檢查過,所以你知道。 – Rawand